Skip to main content

Crate rudo_gc

Crate rudo_gc 

Source
Expand description

A garbage-collected smart pointer library for Rust.

rudo-gc provides a Gc<T> smart pointer with automatic memory reclamation and cycle detection. It uses a BiBOP (Big Bag of Pages) memory layout for efficient O(1) allocation and a Mark-Sweep garbage collection algorithm.

§Features

  • Automatic cycle detection: Unlike Rc<T>, Gc<T> can collect cyclic references
  • BiBOP memory layout: O(1) allocation with size-class based segments
  • Non-moving GC: Address stability for Rust’s &T references
  • Ergonomic API: Similar to Rc<T> with #[derive(Trace)] for custom types

§Quick Start

use rudo_gc::{Gc, Trace};

// Simple allocation
let x = Gc::new(42);
println!("Value: {}", *x);

// Custom types with derive
#[derive(Trace)]
struct Node {
    value: i32,
    next: Option<Gc<Node>>,
}

let node = Gc::new(Node { value: 1, next: None });

§Handling Cycles

use rudo_gc::{Gc, Trace, collect};
use std::cell::RefCell;

#[derive(Trace)]
struct Node {
    next: RefCell<Option<Gc<Node>>>,
}

let a = Gc::new(Node { next: RefCell::new(None) });
let b = Gc::new(Node { next: RefCell::new(None) });

// Create cycle: a -> b -> a
*a.next.borrow_mut() = Some(Gc::clone(&b));
*b.next.borrow_mut() = Some(Gc::clone(&a));

drop(a);
drop(b);
collect(); // Cycle is detected and freed

Re-exports§

pub use cell::GcCell;
pub use cell::GcCapture;
pub use cell::GcThreadSafeCell;
pub use cell::GcThreadSafeRefMut;
pub use gc::incremental::is_incremental_marking_active;
pub use gc::incremental::is_write_barrier_active;
pub use gc::incremental::mark_new_object_black;
pub use gc::incremental::IncrementalConfig;
pub use gc::incremental::IncrementalMarkState;
pub use gc::incremental::MarkPhase;
pub use gc::incremental::MarkSliceResult;
pub use gc::incremental::MarkStats;
pub use sync::GcMutex;
pub use sync::GcRwLock;
pub use gc::collect;
pub use gc::collect_full;
pub use gc::default_collect_condition;
pub use gc::safepoint;
pub use gc::set_collect_condition;
pub use gc::set_gc_enabled;
pub use gc::CollectInfo;
pub use gc::PerThreadMarkQueue;
pub use gc::StealQueue;
pub use handles::AsyncHandle;
pub use handles::AsyncHandleGuard;
pub use handles::AsyncHandleScope;
pub use handles::EscapeableHandleScope;
pub use handles::Handle;
pub use handles::HandleScope;
pub use handles::MaybeHandle;
pub use handles::SealedHandleScope;
pub use metrics::FallbackReason;

Modules§

cell
Interior mutability with write barriers for Generational GC.
gc
Garbage collection coordination and parallel marking.
handles
HandleScope v2 implementation for compile-time safe GC handles.
heap
BiBOP memory management internals.
sync
Concurrent GC primitives for thread-safe garbage-collected objects.

Macros§

impl_gc_capture
Macro to implement GcCapture for types that don’t contain Gc<T> pointers.

Structs§

Ephemeron
An ephemeron is a key-value pair where the value is only reachable if the key is reachable.
Gc
A garbage-collected pointer to a value of type T.
GcBox
The actual heap allocation wrapping the user’s value.
GcHistory
Fixed-size ring buffer of recent GcMetrics snapshots.
GcMetrics
Statistics from the most recent garbage collection.
GlobalMetrics
Process-level cumulative GC statistics.
TraceClosure
A wrapper for a closure that captures and traces dependencies.
Weak
A weak reference to a garbage-collected value.

Enums§

CollectionType
Type of GC collection.

Traits§

Trace
A type that can be traced by the garbage collector.
Visitor
A visitor that traverses the object graph during garbage collection.

Functions§

current_heap_size
Get the current heap size for this thread.
current_old_size
Get the current old generation size for this thread.
current_young_size
Get the current young generation size for this thread.
gc_history
Get the GC history ring buffer.
get_incremental_config
Get the current incremental marking configuration.
global_metrics
Get the global cumulative GC metrics.
is_incremental_gc_enabled
Check if incremental GC is enabled.
last_gc_metrics
Get metrics from the last garbage collection.
scan_heap_region_conservatively
Scan a memory region conservatively for potential Gc pointers.
set_incremental_config
Configure incremental marking settings.
yield_now
Yield to the garbage collector for cooperative scheduling.

Derive Macros§

Trace
Derive macro for the Trace trait.