(i), reference counting method
Explanation: Each object has a reference counter, and when the other declared variables point to the object, the counter is + 1, and when the point disappears, the counter-1. Garbage collection reclaims only objects with a count of 0.
Disadvantage: The case of circular references cannot be recycled, for example a refers to a b,b reference to a c,c reference. This GC algorithm also requires the compiler to mate and count the object references, requiring additional code generation. (ii), Root search algorithm
Explanation: set up a number of root objects, when an object cannot be reached by any of the root object references, then this object can request a "rebirth" opportunity once in finalize, or directly ignore finalize and choose direct death.
GC roots objects include (from memory model analysis): 1. The object referenced in the virtual machine stack . 2. The object that is referenced by JNI in the local method stack . 3. The object referenced by a static type in the method area . 4. The object referenced by the constant in the method area .
So, the question is, how to recycle objects that cannot be "reached" through the root search algorithm.
For:
Algorithm one: Tag-cleanup algorithm (starting from the GC roots tag, Cleanup starts traversing the heap from the heap address, and then finds no marked, and kills, drawbacks: )
Algorithm two: The Replication algorithm (the New Generation (Eden) algorithm used in the heap, also known as minor GC.
Algorithm three: marker-collation Algorithm (collation is to move the memory address on the separated object to the continuous address)