Struct rutie::GC

source ·
pub struct GC;
Expand description

Garbage collection

Implementations§

source§

impl GC

source

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
source

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();
source

pub fn disable() -> bool

Disable the garbage collector

Examples
use rutie::{GC, VM};

let _ = GC::disable();
source

pub fn enable() -> bool

Enable the garbage collector

Examples
use rutie::{GC, VM};

let _ = GC::enable();
source

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);
source

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");
source

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);
source

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);
source

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);
source

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);
source

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);
source

pub fn start()

Start the garbage collector

Examples
use rutie::{GC, VM};

GC::start();
source

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");
source

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);

Auto Trait Implementations§

§

impl RefUnwindSafe for GC

§

impl Send for GC

§

impl Sync for GC

§

impl Unpin for GC

§

impl UnwindSafe for GC

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.