chickadee » chicken » gc » make-finalizer

make-finalizer OBJECT ...procedure

Registers the set of non-immediate argument objects for finalization and returns a procedure of zero or one arguments. Invoking this procedure will return the first object from the set that is not referenced from any other globally reachable data and can be garbage collected. Non-immediate objects are anything that is not a small integer ("fixnum"), a character, a boolean, the empty list, the undefined value, the end-of-file value (#!eof) or the broken-weak-pair object (#!bwp).

Note that you can pass procedures created by make-finalizer to make-finalizer itself, implying that a finalizer procedure is finalized when all associated objects are.

The procedure returned by make-finalizer behaves differently depending on the argument given: If the argument is missing or #f, then it returns #f when no object has as yet been finalized. When the argument is #t, execution of the current thread suspends until a finalization occurs. If no other threads are executing then execution pauses for eternity.

The same caveat regarding weak references applies to finalizers registered with make-finalizer. See NOTE 2 in set-finalizer!.