Trait scoped_gc::Trace
[−]
[src]
pub unsafe trait Trace { unsafe fn mark(&self); unsafe fn root(&self); unsafe fn unroot(&self); }
Used to propagate signals across the objects graph of values managed by the garbage collector.
This trait is unsafe
because an invalid implementations may cause dangling pointers.
For example, if trace
is not propagated to a reachable Gc
pointers then its value may be
freed. The next dereference of this Gc
causes then an error.
You should never initiate the traversal of the object graph: it is the role of the library. Propagating a signal at the wrong time may cause an invalid state leading to dangling pointers.
Required Methods
unsafe fn mark(&self)
Propagates the mark
signal across the objects graph.
This signal is used during the first phase of garbage collection to mark the values that are still reachable.
The signal is initiated at the rooted values and propagated to reach the adjacent Gc
pointers. If their value is not already marked they mark it and propagate the signal further
in the graph.
unsafe fn root(&self)
Propagates the root
signal across the objects graph.
This signal is used to signal that there is a new root pointing to a managed value. This prevents this value (and any other value reachable from it) from being collected.
This is initiated when creating a new Gc
pointer or mutably borrowing the value inside a
GcRefCell
.
unsafe fn unroot(&self)
Propagates the unroot
signal across the objects graph.
This signal is used to signal the destruction of a root pointing to a managed value. If this
was the last root, the value is not longer used to initiate mark
signals: if there are no
other rooted values that can reach it, it becomes eligible for garbage collection.
This is initiated when a Gc
pointer or mutably borrowing the value inside a
GcRefCell
.