Library finalization

This is exported from the core library, which means you don't need to import it.

Support for finalization.

Functions

add-finalizer object/any lambda/any -> none
Registers the given lambda as a finalizer for the object.
Calls the finalizer if all references to the object are lost. (See limitations below).
Errors
It is an error to assign a finalizer to a smi or an instance that already has a finalizer (see remove-finalizer).
It is also an error to assign null as a finalizer.
Warning
Misuse of this API can lead to undefined behavior that is hard to debug.
Advanced
Finalizers are not automatically called when a program exits. This is also true for objects that weren't reachable anymore before the program exited.
An arbitrary amount of time may pass from the object becomes unreachable and the finalizer is called.

remove-finalizer object/any -> bool
Unregisters the finalizer registered for object.
Returns whether the object had a finalizer.