Struct rutie::GC[][src]

pub struct GC;
Expand description

Garbage collection

Implementations

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

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

Disable the garbage collector

Examples

use rutie::{GC, VM};

let _ = GC::disable();

Enable the garbage collector

Examples

use rutie::{GC, VM};

let _ = GC::enable();

Forcibly GC object.

Examples

use rutie::{RString, GC, VM};

let obj = RString::new_utf8("asdf");

GC::force_recycle(obj);

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

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

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

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

Registers the objects address with the GC

Examples

use rutie::{RString, GC, VM};

let object = RString::new_utf8("1");

GC::register(&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);

Start the garbage collector

Examples

use rutie::{GC, VM};

GC::start();

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

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.