Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tracing garbage collection
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== {{Anchor|TRI-COLOR}}Tri-color marking === [[File:Animation of tri-color garbage collection.gif|thumb|upright=1.5| An example of tri-color marking on a heap with 8 objects. White, grey, and black objects are represented by light-grey, yellow, and blue, respectively.]] Because of these performance problems, most modern tracing garbage collectors implement some variant of the ''tri-color marking'' [[abstraction (computer science)|abstraction]], but simple collectors (such as the ''mark-and-sweep'' collector) often do not make this abstraction explicit. Tri-color marking works as described below. Three sets are created{{snd}} ''white'', ''black'' and ''grey'': * The white set, or ''condemned set'', is the set of objects that are candidates for having their memory recycled. * The black set is the set of objects that can be shown to have no outgoing references to objects in the white set, and to be reachable from the roots. Objects in the black set are not candidates for collection. * The grey set contains all objects reachable from the roots but yet to be scanned for references to "white" objects. Since they are known to be reachable from the roots, they cannot be garbage-collected and will end up in the black set after being scanned. In many algorithms, initially the black set starts as empty, the grey set is the set of objects which are directly referenced from roots and the white set includes all other objects. Every object in memory is at all times in exactly one of the three sets. The algorithm proceeds as following: # Pick an object o from the grey set # Move each white object that o references to the grey set. This ensures that neither this object nor any object it references can be garbage-collected. # Move o to the black set # Repeat the last three steps until the grey set is empty. When the grey set is empty, the scan is complete; the black objects are reachable from the roots, while the white objects are not and can be garbage-collected. Since all objects not immediately reachable from the roots are added to the white set, and objects can only move from white to grey and from grey to black, the algorithm preserves an important invariant{{snd}} no black objects reference white objects. This ensures that the white objects can be freed once the grey set is empty. This is called ''the tri-color invariant''. Some variations on the algorithm do not preserve this invariant but use a modified form for which all the important properties hold. The tri-color method has an important advantage{{snd}} it can be performed "on-the-fly", without halting the system for significant periods of time. This is accomplished by marking objects as they are allocated and during mutation, maintaining the various sets. By monitoring the size of the sets, the system can perform garbage collection periodically, rather than as needed. Also, the need to touch the entire working set on each cycle is avoided.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)