pub trait MrbGarbageCollection {
// Required methods
fn create_arena_savepoint(
&mut self,
) -> Result<ArenaIndex<'_>, ArenaSavepointError>;
fn live_object_count(&mut self) -> usize;
fn mark_value(&mut self, value: &Value) -> Result<(), Error>;
fn incremental_gc(&mut self) -> Result<(), Error>;
fn full_gc(&mut self) -> Result<(), Error>;
fn enable_gc(&mut self) -> Result<State, Error>;
fn disable_gc(&mut self) -> Result<State, Error>;
}
Expand description
Garbage collection primitives for an mruby interpreter.
Required Methods§
Sourcefn create_arena_savepoint(
&mut self,
) -> Result<ArenaIndex<'_>, ArenaSavepointError>
fn create_arena_savepoint( &mut self, ) -> Result<ArenaIndex<'_>, ArenaSavepointError>
Create a savepoint in the GC arena.
Savepoints allow mruby to deallocate all the objects created via the C API.
Normally objects created via the C API are marked as permanently alive
(“white” GC color) with a call to mrb_gc_protect
.
The returned ArenaIndex
implements Drop
, so it is sufficient to
let it go out of scope to ensure objects are eventually collected.
Sourcefn live_object_count(&mut self) -> usize
fn live_object_count(&mut self) -> usize
Retrieve the number of live objects on the interpreter heap.
A live object is reachable via top self, the stack, or the arena.
Sourcefn mark_value(&mut self, value: &Value) -> Result<(), Error>
fn mark_value(&mut self, value: &Value) -> Result<(), Error>
Mark a Value
as reachable in the mruby garbage collector.
Sourcefn incremental_gc(&mut self) -> Result<(), Error>
fn incremental_gc(&mut self) -> Result<(), Error>
Perform an incremental garbage collection.
An incremental GC is less computationally expensive than a full GC, but does not guarantee that all dead objects will be reaped. You may wish to use an incremental GC if you are operating with an interpreter in a loop.
Sourcefn full_gc(&mut self) -> Result<(), Error>
fn full_gc(&mut self) -> Result<(), Error>
Perform a full garbage collection.
A full GC guarantees that all dead objects will be reaped, so it is more expensive than an incremental GC. You may wish to use a full GC if you are memory constrained.
Sourcefn enable_gc(&mut self) -> Result<State, Error>
fn enable_gc(&mut self) -> Result<State, Error>
Enable garbage collection.
Returns the prior GC enabled state.
Sourcefn disable_gc(&mut self) -> Result<State, Error>
fn disable_gc(&mut self) -> Result<State, Error>
Disable garbage collection.
Returns the prior GC enabled state.