pub struct Gc<T: Trace> { /* private fields */ }
Expand description
A garbage collector managing objects of type T
.
When dropped, all unrooted objects will be destroyed. Any rooted objects should no longer be used.
Implementations§
source§impl<T: Trace> Gc<T>
impl<T: Trace> Gc<T>
pub fn new() -> Self
pub fn allocate(&mut self, t: T) -> Rooted<T>
sourcepub fn allocate_nocollect(&mut self, t: T) -> Rooted<T>
pub fn allocate_nocollect(&mut self, t: T) -> Rooted<T>
Allocate t
on the garbage-collected heap without triggering a
collection.
sourcepub fn force_full_collect(&mut self)
pub fn force_full_collect(&mut self)
Collect each and every garbage object, atomically.
The root set is determined by taking all objects whose strong reference
count >1
. This only happens during active access (which implies that
the object is still reachable) and because there’s a Rooted
instance
pointing to the object.
As an optimization, whenever we come across an object with a weak count of 0, we know that it has no traced reference pointing to it. If that object also has a strong count of 1, that object isn’t rooted (the only strong reference coming from the GC itself) and can be freed immediately without having to finish the mark phase. Note that this might in turn drop the weak count to other objects to 0 and make them collectible.