Monday, February 19, 2007

Tri-color Marking Garbage Collector

This is one type of garbage collector. This collector working is very simple.
All the references were separated into 3 groups. White, Gray and Black.

Objects that are directly reachable are in White group. (Global , static variables etc). And all the remaining references are put in white. Mostly black list starts empty.

This algorithm works much like a graph traversal.
1. Start with a node in White list.
2. Find all the references that are reachable from this one.
3. Gray those references. If the reference that are reachable from current node, is already in Gray or Black, then move current node to black list. Proceed this until gray node becomes empty.
4. Now, the reference that are still in White list are not reachable, so they all are eligible for garbage collection.

For more information about this see:
http://www.memorymanagement.org/glossary/t.html#tri-color.marking

No comments: