Crates.io | rcgc |
lib.rs | rcgc |
version | 0.1.0 |
source | src |
created_at | 2018-12-19 22:55:21.973312 |
updated_at | 2018-12-19 22:55:21.973312 |
description | A tracing GC in safe Rust based on `Rc` |
homepage | |
repository | https://github.com/jonas-schievink/rcgc.git |
max_upload_size | |
id | 102823 |
size | 28,192 |
This crate implements a pretty simple garbage collector. Its selling point is
that it uses no unsafe
at all: Instead, it represents references between
objects as Weak
pointers that are upgraded to Rc
s on access.
The GC holds an Rc
to every object on its heap and can hand out further Rc
s
acting as roots. It can then locate rooted objects and perform a tracing
garbage collection to free objects with no incoming references (even in the
presence of cycles). It also uses the underlying reference counters as a faster
way to locate garbage objects: If an object has a weak count of 0 and a strong
count of 1, it is only reachable via the GCs own Rc
, not via any object
reference, and can be freed immediately without having to perform a tracing
phase.
If there's a bug in the GC, and an object ends up getting collected while it's
still reachable, any access to the object will fail to upgrade the Weak
pointer and panic instead of becoming an unsafe use-after-free.
Please refer to the changelog to see what changed in the last releases.
Start by adding an entry to your Cargo.toml
:
[dependencies]
rcgc = "0.1.0"
Then import the crate into your Rust code:
extern crate rcgc;