pub struct ThreadedObjectSpace { /* private fields */ }Expand description
A collection of tracked ThreadedCc objects
that can be garbage collected.
ThreadedObjectSpace is similar to
ObjectSpace but works with multi-thread.
Implementations§
Source§impl ThreadedObjectSpace
impl ThreadedObjectSpace
Sourcepub fn count_tracked(&self) -> usize
pub fn count_tracked(&self) -> usize
Count objects tracked by this
ThreadedObjectSpace.
Sourcepub fn collect_cycles(&self) -> usize
pub fn collect_cycles(&self) -> usize
Collect cyclic garbage tracked by this
ThreadedObjectSpace.
Return the number of objects collected.
Sourcepub fn create<T: Trace + Send + Sync>(&self, value: T) -> ThreadedCc<T>
pub fn create<T: Trace + Send + Sync>(&self, value: T) -> ThreadedCc<T>
Constructs a new ThreadedCc<T> in this
ThreadedObjectSpace.
The returned object should not refer to
ThreadedCc<T> created by a different
ThreadedObjectSpace.
Otherwise the collector might fail to collect cycles.
The type T needs to be Send + Sync. This is because the
ThreadedObjectSpace is
Send and Sync. The collector can run in a different
thread to access ThreadedCc<T>, which needs to be
Send + Sync to be safely accessed by the collector.
use gcmodule::{ThreadedObjectSpace, ThreadedCc, Cc};
let cc = Cc::new(5);
let space = ThreadedObjectSpace::default();
let tcc: ThreadedCc<Cc<_>> = space.create(cc);Trait Implementations§
Source§impl Default for ThreadedObjectSpace
impl Default for ThreadedObjectSpace
Source§fn default() -> Self
fn default() -> Self
Constructs an empty ThreadedObjectSpace.