Function in gc compiler

collect

fn collect() -> int
Import
use gc::{collect};
Source: compiler/src/builtin_docs/gc.hy

Runs a full garbage collection now and returns the number of bytes freed.

Collection normally happens on its own; call this to make finalizers (fn drop()) and weak clearing happen at a known point, for example in tests. Values still named by live locals stay alive.

Returns#

int

Examples#

use gc::{collect};
use tests::assert;
let freed = collect();
assert!(freed >= 0);

See also#

  • root: Pins value so the garbage collector keeps it alive while the returned Root is reachable.
  • 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.
↑ ↓ navigate ↵ open