#cc #garbage #mark #sweep #gc

auto-cc

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

#783 in Memory management

MIT license

7KB
62 lines

auto-cc

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::{
    cc,
    
    bacon_rajan_cc::{
        Cc,

        collect_cycles, // for final cleanup, when necessary
    }
};

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

Dependencies

~73KB