Expand description
Mark-sweep garbage collection.
Roots for collection are the active environment and any explicitly named
“live” values (such as the value an evaluator just produced). Marking is
a fold over reachable Addresses; sweeping is delegated to
Heap::retain. Both phases are pure functions: no mut, no interior
mutability, no Rc/Arc.
Address reachability is the transitive closure of:
- Each binding in
envis reachable. - Each value in
rootsis reachable. - From any
Value::Closure, every binding in its captured environment is reachable. - From any
Value::Refwhose address is in the heap, the value at that address is reachable.
Dangling references (a Value::Ref whose address has no heap entry)
are tolerated by the collector: the address is still marked live, since
sweeping cannot create or resolve a dangling ref, only preserve it.
Functions§
- collect
- Retain only the cells reachable from
rootsandenv, returning the resulting heap. The next-address counter is preserved so old addresses continue to detect as dangling rather than colliding with newly-allocated cells. - reachable
- Compute the set of addresses reachable from
rootsandenvthroughheap.