[−][src]Struct gcmodule::ObjectSpace
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
impl !RefUnwindSafe for ObjectSpace
impl !Send for ObjectSpace
impl !Sync for ObjectSpace
impl Unpin for ObjectSpace
impl !UnwindSafe for ObjectSpace
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,