Function in gc compiler

root

fn root<T>(T value) -> Root<T>
Import
use gc::{root};
Source: compiler/src/builtin_docs/gc.hy

Pins value so the garbage collector keeps it alive while the returned Root is reachable.

Parameters#

NameType
valueT

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::Root
  • get: Returns the pinned value, leaving the pin in place.
  • unroot: Releases the pin and returns the value it held.
  • weak: Makes a handle to value that does not keep it alive.
  • upgrade: Returns the value while it is still alive, None once 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.
↑ ↓ navigate ↵ open