I know the CMS garbage collector uses the mark sweep algorithm,I am curious about how it marks the object.
CMS initial mark: why does it mark the reachable objects rather than mark unreachable objects?
I know the CMS garbage collector uses the mark sweep algorithm,I am curious about how it marks the object.
CMS initial mark: why does it mark the reachable objects rather than mark unreachable objects?
The garbage collector's task is to find objects that your program can no longer reach by following whatever chain of accessor steps, and to reclaim the memory occupied by them.
The Mark-Sweep GC does that the other way round: it first finds all objects that can still be reached, and then reclaim the memory of all the other objects.
Simplified Mark-Sweep algorithm (of course the real one is far more complex):