pub struct GC;
Expand description
Garbage collection
Implementations§
source§impl GC
impl GC
sourcepub fn adjust_memory_usage(diff: isize)
pub fn adjust_memory_usage(diff: isize)
Notify memory usage to the GC engine by extension libraries, to trigger GC This is useful when you wrap large rust objects using wrap_data, when you do so, ruby is unaware of the allocated memory and might not run GC
Examples
use rutie::{GC, VM};
GC::adjust_memory_usage(25_000); // Tell ruby that we somehow allocated 25_000 bytes of mem
GC::adjust_memory_usage(-15_000); // Tell ruby that freed 15_000 bytes of mem
sourcepub fn count() -> usize
pub fn count() -> usize
The number of times GC occurred.
It returns the number of times GC occurred since the process started.
Examples
use rutie::{GC, VM};
GC::count();
sourcepub fn force_recycle(object: impl Object)
pub fn force_recycle(object: impl Object)
Forcibly GC object.
Examples
use rutie::{RString, GC, VM};
let obj = RString::new_utf8("asdf");
GC::force_recycle(obj);
sourcepub unsafe fn is_marked(object: &impl Object) -> bool
pub unsafe fn is_marked(object: &impl Object) -> bool
Check if object is marked
CAUTION: THIS FUNCTION IS ENABLED ONLY BEFORE SWEEPING. This function is only for GC_END_MARK timing.
Examples
use rutie::{RString, GC, VM};
let obj = RString::new_utf8("asdf");
GC::mark(&obj);
assert!(unsafe {GC::is_marked(&obj) }, "Object was not marked");
sourcepub fn mark(object: &impl Object)
pub fn mark(object: &impl Object)
Mark an object for Ruby to avoid garbage collecting item.
If the wrapped struct in Rust references Ruby objects, then you’ll have to mark those in the mark callback you are passing to wrapped struct.
Examples
use rutie::{RString, GC, VM};
let object = RString::new_utf8("1");
GC::mark(&object);
sourcepub fn mark_locations(range: &[impl Object])
pub fn mark_locations(range: &[impl Object])
Mark all of the object from start
to end
of the array for the GC.
Examples
use rutie::{RString, GC, VM, AnyObject};
let arr = [
RString::new_utf8("1"),
RString::new_utf8("2"),
RString::new_utf8("3"),
RString::new_utf8("4"),
];
GC::mark_locations(&arr);
sourcepub fn mark_maybe(object: &impl Object)
pub fn mark_maybe(object: &impl Object)
Maybe mark an object for Ruby to avoid garbage collecting item.
If the wrapped struct in Rust references Ruby objects, then you’ll have to mark those in the mark callback you are passing to wrapped struct.
Examples
use rutie::{RString, GC, VM};
let object = RString::new_utf8("1");
GC::mark_maybe(&object);
sourcepub fn register(object: &impl Object)
pub fn register(object: &impl Object)
Registers the objects address with the GC
Examples
use rutie::{RString, GC, VM};
let object = RString::new_utf8("1");
GC::register(&object);
sourcepub fn register_mark(object: &impl Object)
pub fn register_mark(object: &impl Object)
Mark an object as in use for Ruby to avoid garbage collecting item.
If the wrapped struct in Rust references Ruby objects, then you’ll have to mark those in the mark callback you are passing to wrapped struct.
Examples
use rutie::{RString, GC, VM};
let object = RString::new_utf8("1");
GC::register_mark(&object);
sourcepub fn stat(key: &str) -> usize
pub fn stat(key: &str) -> usize
Get the GC stats for a specific key
Note: Will panic if provided an invalid key.
Examples
use rutie::{GC, VM};
let result = GC::stat("heap_allocated_pages");
sourcepub fn unregister(object: &impl Object)
pub fn unregister(object: &impl Object)
Unregisters the objects address with the GC
Examples
use rutie::{RString, GC, VM};
let object = RString::new_utf8("1");
GC::unregister(&object);