gcmodule 0.1.0

Garbage collection support inspired by Python's gc module.
gcmodule-0.1.0 has been yanked.


Garbage collection inspired by CPython's implementation.

This library provides a type Cc<T>. It provides shared reference-counting pointer, similar to stdlib Rc<T>. Unlike Rc, reference cycles in Cc can be collected.


use gcmodule::{Cc, Trace};
use std::cell::RefCell;

type List = Cc<RefCell<Vec<Box<dyn Trace>>>>;
let a: List = Default::default();
let b: List = Default::default();
b.borrow_mut().push(Box::new(a.clone())); // Form a cycle.
drop(b); // Internal values are not dropped due to the cycle.
gcmodule::collect_thread_cycles(); // Internal values are dropped.

Similar Projects

bacon-rajan-cc v0.3

  • Both are reference count, with cyclic garbage collection.
  • Both are single-threaded, and stop-the-world.
  • Main APIs like Cc<T> and Trace are similar, or even compatible.
  • gcmodule is conceptually simpler. There is no need for the "colors" concept.
  • gcmodule does not require extra space for bookkeeping, if all objects are freed by reference counting. See this commit message for some details.