Algorithms in the garbage collection mechanism:
1. Reference counting method: cannot detect a circular reference. If the parent object has a reference to a child object, the child object in turn references the parent object. In this way, their reference count will never be 0.
2 tag-purge algorithm: Scan from the root collection, tag the surviving object object, and then scan the unmarked objects in the entire space for recycling, causing memory fragmentation
3 marker-Collation algorithm : the tag-sweep algorithm is the same way to mark the object, but in the purge of different, after reclaiming the space occupied by the non-surviving objects, all the surviving objects will move to the left free space, and update the corresponding pointer, the object moved, so the cost is higher
4 copying algorithm : Overcomes the overhead of the handle and resolves the garbage collection of heap fragments, it divides the heap into object and free area polygons, and the program pauses execution during the switchover between the object face and the idle area
5 generation (generational) algorithm: objects of different lifecycles can take different recycling algorithms to improve recycling efficiency
A: Young generation: The goal of the young generation is to collect as quickly as possible those objects with short life cycles: Replication
B: Older generations: objects that survive in the young generation after n garbage collection are placed in the old age: older generations are suitable for use with the mark-and-sweep algorithm (or mark-erase-organize)
In-depth understanding of Java garbage collection mechanism