Function in gc compiler

unroot

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

Releases the pin and returns the value it held.

After this the Root no longer keeps the value alive, even if the Root itself is still reachable. A second unroot (or get) returns None.

Parameters#

NameType
pinRoot<T>

Returns#

Option<T>

Examples#

use gc::{root, unroot};
use tests::assert;
let pin = root("once");
assert!(match unroot(pin) { Option::Some(s) => s == "once", Option::None => false });
assert!(match unroot(pin) { Option::Some(_) => false, Option::None => true });

See also#

  • gc::Root
  • gc::get
  • root: Pins value so the garbage collector keeps it alive while the returned Root is reachable.
  • 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