Lua GC until Version 5.
0
● Main drawback of Mark & Sweep: pauses in the
program execution during a GC cycle can be
very long.
In version 5.1, Lua got an incremental
collector. An incremental collector
interleaves the execution of the collector
with the main program.
The Mutator
● From the garbage collector's point of view, the
program is just some nuisance changing the
data it is trying to collect: the mutator!
Tri-color Collector
● Each object is in one of three states: white,
gray, or black.
● Non-visited objects are marked white.
● Visited but not-traversed objects are marked
gray.
● Traversed objects are marked black.
Invariants
● Objects in the root set are gray or black.
● A black object cannot point to a white object.
● Gray objects define the boundary between the
black objects and the white objects.
● Collection advances by traversing gray objects,
turning them black.
– which may create new gray objects
● Collection ends when there are no more gray
objects.