JVM Garbage Collection Policy
1. Static memory allocation and recycling
The memory space is determined at compile time, and the memory space is allocated once the program is loaded. After the program is finished, the corresponding stack frame is revoked, and the allocated static memory space is recycled.
2. Dynamic memory allocation and recycling
The program runs dynamically allocating memory space, which is collected by the garbage collector.
3. Garbage collector
A. Correct detection of garbage objects (key functions)
B. Releasing the memory space occupied by the garbage object
4. Generational-based garbage collection algorithm (hostpot)
Algorithm design ideas:
The objects are grouped by the length of their lifespan (young generation, old age), the newly created objects are allocated in the younger generation, and after several garbage collections, the objects that are still alive are divided into older generations. The collection of older generations is not as frequent as the younger generation, which reduces the number of objects to be scanned at each garbage collection. This improves the efficiency of garbage collection.
Generational-based pairs of structures
The JVM divides the entire heap into young, old, Perm, respectively, to hold objects of different ages.
- Young area: It is divided into the Eden and survivor areas, the newly created objects are in the Eden area, and when the Eden Zone is full, the MINORGC is triggered, and the objects that are still alive in the Eden area are copied to one of the servivor areas. Another surviving object in the Servivor area is copied to this survivor to ensure that there is always an empty servivor area.
- Old area: Servivor area of the object will be triggered MINORGC, the surviving object into the older area, the object in the Servivor area is enough, will be placed directly in the Lao area. FULLGC is triggered when the OID area is full, and the entire heap memory is recycled.
- Perm Area: This place is basically the class object, if a class is loaded frequently may cause the perm area to be full, garbage collection in the perm area is also triggered by FULLGC.
Sun's recommendations for the different generations in the heap:
It is generally recommended that the size of the young area is 1/4for the entire heap, while the survivor area in the young area is generally set to 1/of the entire young area8
<< in-depth analysis of Javaweb Technology Insider >> Reading notes-JVM memory management 2