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

Count objects tracked by this ObjectSpace.

Collect cyclic garbage tracked by this ObjectSpace. Return the number of objects collected.

Constructs a new Cc<T> in this ObjectSpace.

The returned object should only refer to objects in the same space. Otherwise the collector might fail to collect cycles.

Leak all objects allocated in this space

Trait Implementations

Constructs an empty ObjectSpace.

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.