Home  >  Article  >  Java  >  what is java gc

what is java gc

angryTom
angryTomOriginal
2019-11-20 10:12:434414browse

what is java gc

What is java gc

gc refers to the garbage collection mechanism. When an object can no longer be When referenced by subsequent programs, the memory space occupied by this object has no meaning. The Java virtual machine will detect such objects in the memory from time to time, and then reclaim this memory space.

gc is one of the main differences between Java and C/C. When using JAVA, there is generally no need to write special memory recycling and garbage cleaning code. This is because in the Java virtual machine, there is an automatic memory management and garbage cleaning mechanism.

Basic principles of GC:

1. For programmers, using the new keyword allocates memory in the heap, which we call "reachable" ". For GC, as long as all referenced objects are null, we call it "unreachable" and memory will be recycled.

2. When an object is created, the GC begins to monitor the size, memory address and usage of the object. GC uses a directed graph to record and manage all objects in the heap. In this way, it can be clear which objects are reachable and which are not. When it is determined to be unreachable, it is recycled.

3. To ensure the implementation of GC on different platforms, the Java specification does not strictly regulate many of its behaviors. Regarding what algorithm to use, when to recycle, etc.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of what is java gc. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn