rcgc

Crates.iorcgc
lib.rsrcgc
version0.1.0
sourcesrc
created_at2018-12-19 22:55:21.973312
updated_at2018-12-19 22:55:21.973312
descriptionA tracing GC in safe Rust based on `Rc`
homepage
repositoryhttps://github.com/jonas-schievink/rcgc.git
max_upload_size
id102823
size28,192
Jonas Schievink (jonas-schievink)

documentation

https://docs.rs/rcgc/

README

A garbage collector using Rc/Weak

crates.io docs.rs Build Status

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 Rcs on access.

The GC holds an Rc to every object on its heap and can hand out further Rcs 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.

Usage

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;
Commit count: 11

cargo fmt