Struct jrsonnet_gcmodule::ThreadedObjectSpace
source · 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
.