1. The object is not referenced
2. An uncaught exception occurred in the scope
3. The program is executed normally in the scope
4. The program executed System.exit()
5. The program terminates unexpectedly (killed process, etc.)
Two algorithms:Reference counting method, reachability algorithm
There are disadvantages:
There is a circular reference problem.
Four algorithms:Mark removal algorithm、Copy algorithm、Tag sorting algorithm、Generational collection algorithm
The JVM uses:Generational collection algorithm
3. Mark removal algorithm: "Mark-Remove" algorithm is the most basic algorithm. It is divided into two stages: mark and clear: first mark all objects that need to be recycled, and uniformly recycle all marked objects after marking is completed.
There are disadvantages:
Efficiency issues: The marking and removal processes are not efficient.
Space problem: After the mark is cleared, a large number of discontinuous memory fragments will be generated. Too much space fragmentation may cause the program to be unable to find enough continuous memory and have to trigger another garbage in advance when the program needs to allocate large objects in the future operation. Collect actions.
There are disadvantages:
Although the replication algorithm is simple to implement, has high memory efficiency, and is not prone to fragmentation, the biggest problem is that the available memory is compressed to half of the original. And if the number of surviving objects increases, the efficiency of the Copying algorithm will be greatly reduced.
Tag sorting algorithm: Combines the above two algorithms and proposes to avoid defects. The marking phase is the same as the marking cleanup algorithm. After marking, the objects are not cleaned up, but the live objects are moved to one end of the memory. Then clear the objects outside the end boundary.
Generational collection algorithm: Combining the comprehensive analysis of the above three algorithms and the characteristics of the life cycle of JVM memory objects, a new garbage collection algorithm-the generational collection algorithm was born. The core idea is to divide the memory into different domains according to the different life cycles of the object's survival. In general, the GC heap is divided into the Tenured/Old Generation and the Young Generation. The characteristic of the old generation is that only a small number of objects need to be collected during each garbage collection, and the characteristic of the new generation is that a large amount of garbage needs to be collected during each garbage collection, so different algorithms can be selected according to different regions.
The new generation-replication algorithm: Because most of the objects in the new generation are collected every time garbage collection, that is, there are fewer operations to copy, but the new generation is usually not divided according to 1:1. Generally, the new generation is divided into a larger Eden space and two smaller Survivor spaces (From Space/S1, To Space/S2). Each time the Eden space and one of the Survivor spaces are used, when reclaiming, the The surviving objects in the two spaces are copied to the other Survivor space.
Old age-mark copy algorithm:

The 3 groups are:Serial and Serial Old, PS and PO, ParNew and CMS

STW: Stop temporarily until the thread is cleaned up before continuing.
Serial and Serial Old operating modes: temporarily stop and waitSingle threadIf the cleaning is over and then continue, there will be a stuttering phenomenon.
PS and PO operating modes: temporarily stop and waitMultithreadingIf the cleaning is over and then continue, there will be a stuttering phenomenon.
jdk1.7/1.8 default garbage collectorPS and POCombination, how to query the type of garbage collector:
java -XX:+PrintCommandLineFlags -version;The full name of CMS: concurrent mark sweep, its meaning is to solveSTW stuttering phenomenon, ParNew is specifically designed to work with CMS, ParNew is approximately equal to PS, but the only difference is that it has enhanced modules for PS.
Several stages of CMS work:
There are disadvantages:
Fragmentation of memory; if the execution of the object from the young generation to the old generation fails, Serial Old will be executed again for defragmentation. If floating garbage is generated, it can only wait for the next GC collection process.
Briefly talk about the next several garbage collectors, which contain a lot of my personal understanding, it is inevitable that there are errors and omissions, please correct me Borrow a picture New g...
Ten common garbage collectors: Serial, SerialOld, ParallelScavenger, ParallelOld, ParNew, CMS, G1, ZGC, Shenandoah, Epsilon. Serial, SerialOld, ParallelScavenger, ParNew, CMS are all physically and lo...
Evaluate GC performance indicators // Mainly based on throughput and pause time evaluation Throughput: the percentage of time spent running user code in total...
Garbage collector Overview Rubbish: There is no object pointed to by any pointer in the running program, and this object is garbage that needs to be recycled. Garbage collection period: The garbage co...
What are the common garbage collectors of Java? The garbage collection mechanism is Java's signature ability, which greatly improves development efficiency. Nowadays, garbage collection has almost bec...
introduction:If the collection algorithm is a method of memory recycling, the garbage collector is the concrete implementation of memory recycling. Serial collector The serial collector is the ...
Common GC algorithms Reference counting: Every object has a counter, the object is referenced once, the counter is +1, when the object reference fails once. The counter -1, when the object counter is ...
1. Common GC algorithms 1. Mark-clearing algorithm Mark the objects that need to be recycled and then clean them directly in GC. Disadvantages: It will cause a large number of discontinuous memory fra...
1.GC (Garbage Collection) java garbage collection is an automatic process to manage the runtime memory used by programs.by doing it automatic JVM relieves the programer of the overhead of assigning an...
Four GC algorithms Overview Reference counting Copying algorithm (Copying) Mark-Sweep Mark compression algorithm (Mark-Compact) to sum up Overview When JVM is performing GC,The above three memory area...