Tag-Purge algorithm
The algorithm is divided into two phases: marking and purging, first marking all objects that need to be recycled, and then uniformly reclaiming all tagged objects after the tag is complete.
Disadvantages of this algorithm:
1, efficiency issues: marking and clearing two processes are not efficient
2. Space problem: After the mark is cleared, there will be a lot of discontinuous memory fragmentation, too much memory fragmentation may be the later when the program is running, you need to allocate large objects, you cannot find enough contiguous memory and have to trigger another garbage collection in advance.
Replication Algorithms
In order to solve the problem of recycling efficiency, the replication algorithm is introduced. It divides the available memory by capacity into two blocks of equal size, using only one piece at a time. When this piece of memory is used up, the surviving object is copied to the other piece, and then the memory space that has been used is cleaned out once. In this way, each collection recycles the entire half of the area, regardless of the complexity of the memory fragments, just move the heap pointers and allocate the memory sequentially.
Disadvantages:
The cost of this algorithm is to reduce the memory to half the original, wasting space.
A more detailed explanation of the replication algorithm can be found in: Talk about the younger generation of the JVM
Tagging-sorting algorithms
The replication algorithm is suitable for low-survival algorithms in the Cenozoic. But for this region of the old age, efficiency will be lower. So in the old years, the general use of marker-collation algorithm
Tag-the markup and markup in the algorithm-the same as the markup in the cleanup, but the grooming step is not to clean up the tagged object directly, but to let all surviving objects move toward one end and then clean out the memory outside the boundary.
Generational collection Algorithms
The Generational collection algorithm divides memory into extremely fast based on the lifetime of the object. In general, the Java heap is divided into the new generation and the old age, so that you can use the most appropriate collection algorithm according to the characteristics of each age. In the new generation, the replication algorithm is used to recycle the "mark-clean" algorithm or the "mark-tidy" algorithm in the old age.
A step-by-step study of jvm-garbage collection algorithm