cabbage_collector 0.1.1

ready
Documentation
  • Coverage
  • 8.33%
    1 out of 12 items documented0 out of 4 items with examples
  • Size
  • Source code size: 12.19 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • myyrakle/cabbage_collector
    1 0 5
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • myyrakle

Cabbage Collector

  • Simple GC implementation
  • Simple Mark and Sweep

Guide

The way to create and use the object is almost the same as Box<T>. However, in the current implementation, GC must be triggered manually.

    {
        #[derive(Debug, Clone)]
        struct A {
            pub value: i32,
        }

        let child_obj = CabbageBox::new(A { value: 1 });
        println!("{:?}", child_obj);
    }
    COLLECTOR.run_cabbage_collection();

The circular reference issue has been resolved.

    {
        #[derive(Debug, Clone)]
        struct A {
            pub value: Option<CabbageBox<B>>,
        }

        #[derive(Debug, Clone)]
        struct B {
            pub value: Option<CabbageBox<A>>,
        }

        let mut a_obj = CabbageBox::new(A { value: None });
        let mut b_obj = CabbageBox::new(B { value: None });

        a_obj.value = Some(b_obj.clone());
        a_obj.adopt_child(b_obj.clone());

        b_obj.value = Some(a_obj.clone());
        b_obj.adopt_child(a_obj.clone());
    }
    COLLECTOR.run_cabbage_collection();

Checklist

  • Circular Reference
  • Automatically identifies root and non-root
  • Auto trigger GC
  • Concurrent GC
  • Generational GC
  • Memory Compaction