pub struct Tracer<'a> { /* private fields */ }Expand description
The sink a Trace implementation reports its outgoing edges to.
A Tracer is handed to Trace::trace during a collection. Its one job is to
receive handles: each call to mark records that the object
being traced points at another, so the collector can visit it in turn. It holds
a borrow of the collector’s work queue and nothing else, so recording an edge is
a single push — no allocation on the steady-state path, since the queue is
reused across collections.
You never construct a Tracer; the heap builds one and passes it in.
Implementations§
Source§impl<'a> Tracer<'a>
impl<'a> Tracer<'a>
Sourcepub fn mark<T>(&mut self, handle: Gc<T>)
pub fn mark<T>(&mut self, handle: Gc<T>)
Records that the object being traced holds handle, so the collector will
visit — and thereby keep alive — the object it names.
Call this once for every handle the object owns. Marking a handle that does not name a live object is harmless: the collector rejects it when it reaches the front of the queue. The generic parameter lets a value mix handles into several heaps; each is validated against its own heap when that heap collects.
§Examples
use gc_lang::{Gc, Trace, Tracer};
struct Cell {
next: Option<Gc<Cell>>,
}
impl Trace for Cell {
fn trace(&self, tracer: &mut Tracer<'_>) {
if let Some(next) = self.next {
tracer.mark(next);
}
}
}