1 unstable release
Uses new Rust 2024
| 0.1.3 | Apr 12, 2026 |
|---|---|
| 0.1.2 |
|
| 0.1.1 |
|
| 0.1.0 |
|
#339 in Memory management
87KB
2K
SLoC
Gomi 
Warning
Gomi is still in early development and extremely experimental. Feedback is highly appreciated.
Gomi is a conservative mark-sweep collector written in Rust. It's supposed to be a drop-in, low overhead addition to the language.
Gomi doesn't require any custom trait implementations and may not even require a custom allocator in the future. For now though it does.
Allocating values using gomi::new yields so-called "managed references". Whether a reference is managed or not is completely opaque to the application and as such it can be used like any regular reference.
While managed references can be used pervasively, they're intended to be used only when needed. Avoid using managed references where regular references, Rc or Box would be equally usable.
Supported architectures
- x86_64
- aarch64
Supported operating systems
- Linux
- macOS
- Windows 11
Example usage
use std::{collections::HashMap, sync::OnceLock};
use gomi::new;
// Without this references stored in unmanaged buffers won't be marked as reachable.
#[global_allocator]
static ALLOCATOR: gomi::Allocator = gomi::Allocator;
type TypeRef = &'static Type;
enum Type {
Number,
Reference(TypeRef),
Struct {
name: String,
fields: OnceLock<HashMap<String, TypeRef>>,
},
}
fn main() {
let mut s = None;
for _ in 0..1000 {
let struct_t = &*new(Type::Struct {
name: "TheStruct".into(),
fields: OnceLock::new(),
});
if let Type::Struct { fields, .. } = struct_t {
fields
.set(HashMap::from_iter([(
String::from("self_ref"),
&*new(Type::Reference(struct_t)),
)]))
.unwrap();
}
s = Some(struct_t);
}
// Likely 2000, depending on the available memory.
eprintln!("Objects: {}", gomi::live_objects_count());
// Forces collection of all* dangling managed allocations.
// Calling this isn't necessary, this is just a demonstration.
gomi::force_collection();
// Likely 2, depending on the behaviour of the system allocator and whether or not there are false positives.
eprintln!("Objects: {}", gomi::live_objects_count());
}
Dependencies
~0.4–30MB
~477K SLoC