1, Mark clear algorithm: First mark out all the objects that need to be recycled, after the mark is complete, all the tagged objects are collected uniformly. The disadvantage is the efficiency problem and the large amount of discontinuous memory fragmentation, which causes the program to allocate large objects at a later time without enough contiguous memory to be found and has to go ahead with another garbage collection action.
2. Copy algorithm: Divide the available memory into two blocks of equal size, use only one of them at a time, and when this piece of memory is used up, copy the surviving objects to the other, then clean up the used memory space once.
3. Labeling algorithm: Let all surviving objects move toward one end, and then directly clean out the memory outside the end boundary.
The current commercial virtual machine garbage collection is a generational collection algorithm: According to the different life cycle of the object to divide the memory into several blocks, generally the Java heap is divided into the new generation and the old age, so you can use the most appropriate collection algorithm according to the characteristics of each era, in the Cenozoic, each garbage collection found that a large number of objects died , only a small amount of survival, then choose the replication algorithm, only a small number of surviving objects can be copied cost to complete the collection. In the old age, because of the high survival rate of the object and the lack of additional space to guarantee it, it must be recycled using either a tag cleanup or a tagging algorithm.
Copyright NOTICE: This article is the original blogger article, reproduced please indicate the source: Http://blog.csdn.net/lingzhm
Java Virtual machine garbage collection algorithm