3 unstable releases
Uses new Rust 2024
new 0.1.1 | May 10, 2025 |
---|---|
0.1.0 | Apr 20, 2025 |
0.0.0 | Apr 13, 2025 |
#262 in Memory management
281 downloads per month
13KB
303 lines
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