This is fork of https://github.com/quark-zju/gcmodule package, which implements several features for usage in jrsonnet
Garbage collection inspired by CPython's implementation.
This library provides a type
Cc<T>. It provides shared reference-counting pointer, similar to stdlib
Rc, reference cycles in
Cc can be collected.
If all values 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 ; use RefCell; type List = ; let a: List = Defaultdefault; let b: List = Defaultdefault; a.borrow_mut.push; b.borrow_mut.push; // Form a cycle. drop; drop; // Internal values are not dropped due to the cycle. collect_thread_cycles; // Internal values are dropped.
For customized structures, they need to implement the
Trace interface. That can be done by
use ; use RefCell; ; assert_eq!; // 2 values are collected.
Refer to the documentation for more examples and technical details.
- Both are reference counted, with cyclic garbage collection.
- Both are mainly single-threaded, and stop-the-world.
- Main APIs like
Traceare similar, or even compatible.
gcmoduleis conceptually simpler. There is no need for the "colors" concept.
ThreadedCc<T>for multi-thread environment.
bacon-rajan-ccrequires 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.
rcgctakes a novel approach - the collector holds strong references while everywhere else uses weak references.
rcgcrequires manual collection to release actual objects even if the reference count of objects (logically) drops to 0.