cabbage_collector

Crates.iocabbage_collector
lib.rscabbage_collector
version0.1.1
created_at2025-04-13 16:20:42.889059+00
updated_at2025-05-10 18:57:24.821281+00
descriptionready
homepagehttps://github.com/myyrakle/cabbage_collector/blob/master/README.md
repositoryhttps://github.com/myyrakle/cabbage_collector
max_upload_size
id1631957
size12,671
myyrakle (myyrakle)

documentation

https://github.com/myyrakle/cabbage_collector/blob/master/README.md

README

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
Commit count: 43

cargo fmt