Mark-sweep algorithm
The tag-purge (Mark-sweep) algorithm is divided into two phases: Mark and purge, which mark all objects that need to be recycled, and then uniformly reclaim all the tagged objects after the tag is complete. This algorithm mainly has two disadvantages: 1. The mark and purge process is less efficient 2. A large number of discontinuous memory fragments are generated after the tag is purged. Because of the excessive space fragmentation, it is possible that the program will not be able to find enough contiguous memory space when it needs to allocate large objects during the run, causing another garbage collection action to be violated.
Coping algorithm
The replication algorithm 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 is already used is cleaned out once. Coping algorithm is only a piece of memory recovery, memory allocation without considering the problem of memory fragmentation, the implementation of simple, efficient operation. The cost of this algorithm is to reduce the memory to the original half, the space use efficiency is not high.
Mark-compact algorithm
The high survival rate of the replication algorithm is that many replication operations are performed and the efficiency becomes low. In the old age of the object general life cycle is relatively long, generally not suitable for the use of replication algorithm. According to the survival characteristics of the old-age object, the "Mark-Organize" (mark-compact) algorithm emerges. The tagging process for the mark-compact algorithm is the same as the mark-sweep algorithm, but the next step is not to reclaim the object directly, but to let the surviving object move toward one end and then clean out the memory outside the end boundary.
Bibliography:
"In-depth understanding of Java Virtual machines: JVM advanced features and best practices"
"Deep Java Virtual machine"
Garbage collection algorithm