Home > Java > Javagetting Started > What is java's gc

What is java's gc

(*-*)浩
Release: 2019-11-14 09:32:27
Original
2821 people have browsed it

An excellent Java programmer must understand the working principle of GC, how to optimize the performance of GC, and how to have limited interaction with GC. Some applications have higher performance requirements, such as embedded systems, real-time systems, etc., only Only by comprehensively improving memory management efficiency can the performance of the entire application be improved.

What is java's gc

This article will discuss the working principle of GC, several key issues of GC, and finally put forward some Java program design suggestions on how to improve the performance of Java programs from the perspective of GC.

What is GC? Why is there a GC? (Recommended learning: java course)

GC means garbage collection (Garbage 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 monitor whether the object exceeds the scope to achieve automatic recycling. The purpose of memory, the Java language does not provide an explicit operation method to release allocated memory.

So, Java's memory management is actually the management of objects, including the allocation and release of objects.

For Java programmers, allocate objects using the new keyword; when releasing an object, just assign all references to the object to null so that the program can no longer access the object. We call the object " Unreachable". GC will be responsible for reclaiming the memory space of all "unreachable" objects.

For GC, when the programmer creates an object, GC begins to monitor the address, size and usage of the object. Usually, GC uses a directed graph to record and manage all objects in the heap.

In this way, determine which objects are reachable and which objects are; unreachable. When the GC determines that some objects are unreachable, the GC is responsible for reclaiming these memory spaces.

However, in order to ensure that GC can be implemented on different platforms, the Java specification does not strictly stipulate many behaviors of GC.

For example, there are no clear regulations on important issues such as what type of recycling algorithm to use and when to perform recycling.

Therefore, different JVM implementers often have different implementation algorithms. This also brings a lot of uncertainty to the development of Java programmers. This article studies several issues related to GC work and strives to reduce the negative impact of this uncertainty on Java programs.

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template