docs.rs failed to build gc-lite-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
GC Lite
A Partitioned Garbage Collector.
Features
- Flat Partition: Supports multiple independent partitions without parent-child hierarchical relationships
- Root Objects: Objects within each partition can be independently set as root objects
- Mark-Sweep: Implements classic garbage collection algorithm
- Weak Reference: Provides weak reference mechanism to avoid memory leaks caused by circular references
- Type Safety: Ensures memory safety through Rust's type system
Core Components
- GcHeap: Garbage collection heap, manages the lifecycle of all partitions and objects
- PartitionId: Partition identifier
- PartitionInfo: Partition information including memory usage
- Gc: GC pointer wrapper providing safe object access
- GcRef: Underlying GC reference for internal operations
- GcWeak: Weak reference that doesn't prevent object collection
- GcTracable trait: Defines behavior that objects to be garbage collected must implement
Basic Usage
use ;
Partition Management
use ;
let mut heap = new;
// Create partitions
let partition1 = heap.create_partition;
let partition2 = heap.create_partition;
// Get partition information
if let Some = heap.partition
// Delete partition (must be empty)
heap.remove_partition;
// Automatic garbage collection (all partitions needing GC)
let total_freed = heap.collect_garbage_auto;
Root Object Management
use ;
// Create regular object
let obj = heap.alloc.map_err?;
// Set as root object
heap.set_root;
// Clear root object status
heap.set_root;
// Directly create root object
let root_obj = heap.alloc.map_err?;
heap.set_root;
Weak References
use ;
let obj = heap.alloc.map_err?;
heap.set_root;
// Create weak reference
let weak_ref = heap.downgrade;
// Try to upgrade weak reference
match weak_ref.upgrade
Custom Types
To use custom types, implement the GcTracable trait:
use GcTracable;
unsafe
Running Examples
# Run basic usage example
# Run tests
Notes
- All objects on the heap must implement the
GcTracabletrait - Only root objects or objects referenced by root objects (directly or indirectly) will be retained
- Weak references don't prevent objects from being garbage collected
- Circular references can be broken through weak references
- Default partitions cannot be deleted
- Partitions must be empty to be deleted