Module compiler

gc

Coil’s heap is garbage collected; most programs never touch this module. Use it when native code holds on to a Coil value (root it), when a registry should not keep its entries alive (weak and upgrade), or to measure memory (heap_bytes, collect).

A class or enum can define fn drop() to release a native resource when its value becomes unreachable. A collection marks everything reachable, runs the drop of unreachable values (each at most once), clears Weak handles whose value is gone, then frees memory. A Weak to an immediate value (an int, a bool) always upgrades. Root and Weak cannot be sent to another thread.

Built into the compiler.

Import what you use (use path::* is not allowed):

use gc::{Root, Weak};

Types#

NameDescription
RootA strong pin that keeps a value alive, made by root.
WeakA handle that refers to a value without keeping it alive, made by weak.

Functions#

NameDescription
rootPins value so the garbage collector keeps it alive while the returned Root is reachable.
getReturns the pinned value, leaving the pin in place.
unrootReleases the pin and returns the value it held.
weakMakes a handle to value that does not keep it alive.
upgradeReturns the value while it is still alive, None once it was collected.
heap_bytesReturns the size of the managed heap in bytes.
collectRuns a full garbage collection now and returns the number of bytes freed.
↑ ↓ navigate ↵ open