tag-purge algorithm:This is the most basic, is the previous two times the mark, first mark out all the objects that need to be recycled, and then do a unified cleanup,This has two drawbacks: one is inefficient, marking and purging (turning on low priority for recycling) is inefficient. The second is the space problem, where tag cleanup generates a lot of memory fragmentation. Replication algorithm:you can divide the memory into two blocks of equal size, using only one block at a time, and when a fast memory is exhausted, move the surviving object to another piece,The used piece is then recycled with the garbage collector. This is a simple and efficient way to operate. The disadvantage is that the actual usage size of the memory is reduced. For example, using 20M of memory, you can only use 10M each time. and in the case where the object is more alive, it is necessary to perform more replication operations, and the efficiency will be reduced. tag-Collation algorithm:The tagging process is still the same as the mark-sweep algorithm, where objects are organized and all objects are moved to the net, and then the memory outside the end boundary is cleaned up directly . Generational collection algorithm:Modern commercial virtual machines mostly use the generational collection algorithm, which divides the memory into different blocks depending on the life cycle of the object.in general, the Java heap is divided into the new generation and the old age, in the new generation of garbage collection every time the discovery of a large number of objects died,only a small amount of survival, and then select the replication algorithm, so that only a small number of objects to survive the cost of replication can be done to complete the collection,in the old age, because of the high survival rate of the object, there is no additional space to guarantee it, you must use the tag-cleanup algorithm to reclaim
Garbage collection algorithm of Java Virtual machine