#cc #garbage #gc #mark #sweep #object


A small utility to perform automatic cycle collections with bacon_rajan_cc

2 unstable releases

0.2.0 Dec 28, 2019
0.1.0 Dec 26, 2019

#727 in Memory management

MIT license

62 lines


A small utility to perform automatic cycle collections on bacon_rajan_cc objects when necessary.

This is intended for scenarios where precisely controlling the shape of data structures is impractical or impossible, and large numbers of cycles are likely to happen outside of the programmer's control such as values in a VM/interpreter for a scripting language implementation.

The logic for checking and collecting roots is only contained in the cc function (calling Cc::new() as per usual will not trigger the check).

Cc::new() should be preferred for short-lived code, or code where little to no cycles are likely to be created.

It is important to note that cycles are collected before a new Cc<T> is allocated, so it is possible that a dead cycle could still remain after the untrusted code has finished execution, and a manual call to the collect_cycles function from the bacon_rajan_cc crate to perform final cleanup is recommended.

Basic Example

extern crate auto_cc;

use auto_cc::{

        collect_cycles, // for final cleanup, when necessary

fn main() {
    let _x: Cc<u8> = cc( 0 );