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, TraceBox};
use std::cell::RefCell;
let mut space = ObjectSpace::default();
assert_eq!(space.count_tracked(), 0);
{
type List = Cc<RefCell<Vec<TraceBox<dyn Trace>>>>;
let a: List = space.create(Default::default());
let b: List = space.create(Default::default());
a.borrow_mut().push(TraceBox(Box::new(b.clone())));
b.borrow_mut().push(TraceBox(Box::new(a.clone())));
}
assert_eq!(space.count_tracked(), 2);
assert_eq!(space.collect_cycles(), 2);Implementations§
Source§impl 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§
Source§impl Default for ObjectSpace
impl Default for ObjectSpace
Source§fn default() -> Self
fn default() -> Self
Constructs an empty ObjectSpace.
Auto Trait Implementations§
impl !Freeze for ObjectSpace
impl !RefUnwindSafe for ObjectSpace
impl !Send for ObjectSpace
impl !Sync for ObjectSpace
impl Unpin for ObjectSpace
impl UnsafeUnpin for ObjectSpace
impl !UnwindSafe for ObjectSpace
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more