GC means garbage collection (Gabage Collection). Memory processing is where programmers are prone to problems. Forgotten or wrong memory recycling can lead to instability or even crash of the program or system. .
The GC function provided by Java can automatically detect whether the object exceeds the scope to achieve the purpose of automatically reclaiming memory. The Java language does not provide a display operation method to release allocated memory.
GC is the garbage collector. Java programmers don't have to worry about memory management because the garbage collector takes care of it automatically. To request garbage collection, call one of the following methods:
·System.gc()
##· Runtime.getRuntime().gc()
Java is developed from C. It abandons some of the cumbersome and error-prone things in C. One of them is this GC. When writing a C/C program, the programmer defines a variable, which means opening up a corresponding space in the memory to store the value. No matter how large the memory is, it is limited, so when the program no longer needs to use a certain variable, it needs to release this memory space resource so that other variables can use it. In C/C, the issue of releasing useless variable memory space must be solved by the programmer himself. That is to say, when the programmer thinks that the variable is useless, he should write a code to release the memory it occupies. In this way, memory leaks and resource waste can be avoided to the greatest extent. But this is obviously very cumbersome. When the program is relatively large and there are many variables, programmers often forget to release the memory or release the memory when they should not be released. Moreover, releasing memory should not be something that programmers should pay attention to from a development perspective. What programmers have to do should be to implement the required program functions instead of spending a lot of energy on allocating and releasing memory. With GC in Java, programmers do not need to manually release memory space. When the Java virtual machine finds that memory resources are tight, it will automatically clean up the memory space occupied by useless variables. Of course, if necessary, programmers can explicitly use System.gc() in a Java program to force an immediate memory cleanup. Because the explicit declaration is to do a full scan of the heap memory, that is, Full GC, all activities need to be stopped (Stop The World Collection). Can your application withstand this? It shows that calling System.gc() is just a suggestion to the virtual machine and may not be executed because System.gc() is executed in a thread with a very low priority. php Chinese website, a large number of freeJava introductory tutorials, welcome to learn online!
The above is the detailed content of What is gc in java. For more information, please follow other related articles on the PHP Chinese website!

Golang的垃圾回收(GC)一直是开发者们关注的一个热门话题。Golang作为一门快速的编程语言,其自带的垃圾回收器能够很好地管理内存,但随着程序规模的增大,有时候会出现一些性能问题。本文将探讨Golang的GC优化策略,并提供一些具体的代码示例。Golang中的垃圾回收Golang的垃圾回收器采用的是基于并发标记-清除(concurrentmark-s

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于设计模式的相关问题,主要将装饰器模式的相关内容,指在不改变现有对象结构的情况下,动态地给该对象增加一些职责的模式,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
