The Java platform automates memory management through the garbage collector (GC) and is primarily responsible for completing 3 tasks: allocating memory, ensuring that the referenced object's memory is not being reclaimed incorrectly, and reclaim memory space for objects that are no longer referenced. In general, the execution of the entire application is temporarily aborted when the garbage collector is in the recycling operation. Because the garbage collector is updating the actual memory address referenced by all objects in the app. The garbage collection methods supported by different hardware platforms are also different.
The most basic method of garbage collection is recycling. Memory is divided into generations (young, old, and permanent), objects are stored in the corresponding generation region according to their survival time, and different generations of garbage collection algorithms vary. Memory allocations occur in young generations. When an object survives long enough, it is copied to the old age.
Java provides 3 kinds of garbage collection mechanisms:
Serial Recycling : Use a single CPU to reclaim the memory of younger and older generations, suitable for a typical single CPU desktop platform. During the garbage collection process, the application is temporarily aborted. Recycling is using generational recycling.
Parallel Recycling : When a young generation is recycled in this way, multiple CPU parallel processing is used to improve recovery performance. Out;
parallel tagging--clear recycle : You can tag live objects and recycle garbage while the app is running, just for a short time to abort the application, which is appropriate for applications with high response time requirements.
Java garbage collection mechanism