Struct jrsonnet_gcmodule::ObjectSpace
source · [−]pub struct ObjectSpace { /* private fields */ }
Expand description
Provides advanced explicit control about where to store Cc
objects.
An ObjectSpace
provides an alternative place for
a collection of Cc
objects. Those objects are isolated from
the default thread-local space used by objects crated via Cc::new
.
The objects in this space can be collected by
ObjectSpace::collect_cycles()
,
but not collect_thread_cycles
.
Use ObjectSpace::create
to
create new objects within the space.
Objects within a space should not refer to objects in a different space. Failing to do so might cause memory leak.
Example
use jrsonnet_gcmodule::{Cc, ObjectSpace, Trace};
use std::cell::RefCell;
let mut space = ObjectSpace::default();
assert_eq!(space.count_tracked(), 0);
{
type List = Cc<RefCell<Vec<Box<dyn Trace>>>>;
let a: List = space.create(Default::default());
let b: List = space.create(Default::default());
a.borrow_mut().push(Box::new(b.clone()));
b.borrow_mut().push(Box::new(a.clone()));
}
assert_eq!(space.count_tracked(), 2);
assert_eq!(space.collect_cycles(), 2);
Implementations
sourceimpl ObjectSpace
impl ObjectSpace
sourcepub fn count_tracked(&self) -> usize
pub fn count_tracked(&self) -> usize
Count objects tracked by this ObjectSpace
.
sourcepub fn collect_cycles(&self) -> usize
pub fn collect_cycles(&self) -> usize
Collect cyclic garbage tracked by this ObjectSpace
.
Return the number of objects collected.
Trait Implementations
sourceimpl Default for ObjectSpace
impl Default for ObjectSpace
sourcefn default() -> Self
fn default() -> Self
Constructs an empty ObjectSpace
.
Auto Trait Implementations
impl !RefUnwindSafe for ObjectSpace
impl !Send for ObjectSpace
impl !Sync for ObjectSpace
impl Unpin for ObjectSpace
impl !UnwindSafe for ObjectSpace
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more