[][src]Struct gcmodule::ObjectSpace

pub struct ObjectSpace { /* fields omitted */ }

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 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);

Methods

impl ObjectSpace[src]

pub fn count_tracked(&self) -> usize[src]

Count objects tracked by this ObjectSpace.

pub fn collect_cycles(&self) -> usize[src]

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

pub fn create<T: Trace>(&self, value: T) -> Cc<T>[src]

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.

Trait Implementations

impl Default for ObjectSpace[src]

fn default() -> Self[src]

Constructs an empty ObjectSpace.

impl Drop for ObjectSpace[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.