gcmodule 0.1.1

Cyclic garbage collection inspired by CPython's gc implementation.
gcmodule-0.1.1 has been yanked.


Documentation crates.io Build Status

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.

If all values (Ts) can be freed by just reference-counting, the collector used by this library does not take extra memory. This is different from some other implementations, which require manual collection to free the extra memory used by the collector.


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 counted, 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 requires manual collection to release GC metadata (but not the tracked object) even if the reference count logically drops to 0. See this commit message for some details.


  • rcgc takes a novel approach - the collector holds strong references while everywhere else uses weak references.
  • Therefore, rcgc requires manual collection to release actual objects even if the reference count of objects (logically) drops to 0.