root
fn root<T>(T value) -> Root<T> Import
Source: use gc::{root}; compiler/src/builtin_docs/gc.hy Pins value so the garbage collector keeps it alive while the returned Root is reachable.
Parameters#
| Name | Type |
|---|---|
value | T |
Returns#
Root<T>
Examples#
use gc::{root, get};
use tests::assert;
let pin = root("kept");
assert!(match get(pin) { Option::Some(s) => s == "kept", Option::None => false });
See also#
gc::Rootget: Returns the pinned value, leaving the pin in place.unroot: Releases the pin and returns the value it held.weak: Makes a handle tovaluethat does not keep it alive.upgrade: Returns the value while it is still alive,Noneonce it was collected.heap_bytes: Returns the size of the managed heap in bytes.collect: Runs a full garbage collection now and returns the number of bytes freed.