| Crates.io | abfall |
| lib.rs | abfall |
| version | 0.1.0 |
| created_at | 2025-11-15 08:20:34.025097+00 |
| updated_at | 2025-11-15 08:20:34.025097+00 |
| description | Concurrent tri-color tracing garbage collector for Rust with incremental and concurrent mark-sweep |
| homepage | https://github.com/HellButcher/abfall |
| repository | https://github.com/HellButcher/abfall |
| max_upload_size | |
| id | 1934144 |
| size | 130,090 |
A concurrent mark-and-sweep garbage collector library for Rust using the tri-color marking algorithm.
The garbage collector uses a tri-color marking scheme:
Mark Phase: Starting from root objects, the GC marks all reachable objects by:
Sweep Phase: Reclaim memory from white (unmarked) objects
use abfall::{GcContext, GcPtr};
use std::sync::Arc;
// Create a new GC context with automatic background collection
let ctx = GcContext::new();
// Allocate objects on the GC heap
let value1 = ctx.allocate(42);
let value2 = ctx.allocate("Hello, GC!");
let value3 = ctx.allocate(vec![1, 2, 3, 4, 5]);
// Access values through smart pointers
println!("Value: {}", *value1);
println!("String: {}", *value2);
println!("Vector: {:?}", *value3);
// When pointers go out of scope, objects become unreachable
// and will be collected in the next GC cycle
use abfall::GcContext;
use std::time::Duration;
// Create context without background collection
let ctx = GcContext::with_options(false, Duration::from_millis(100));
let ptr = ctx.allocate(100);
drop(ptr); // Object is now unreachable
// Manually trigger collection
ctx.collect();
use abfall::GcContext;
use std::sync::Arc;
use std::thread;
let ctx = Arc::new(GcContext::new());
let mut handles = vec![];
for i in 0..10 {
let ctx_clone = Arc::clone(&ctx);
let handle = thread::spawn(move || {
// Allocate from multiple threads
let ptr = ctx_clone.allocate(i);
println!("Thread {} allocated: {}", i, *ptr);
});
handles.push(handle);
}
for handle in handles {
handle.join().unwrap();
}
This project is licensed under either of
at your option
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the project by you shall be dual licensed as above, without additional terms or conditions.