SRFI 254: Ephemerons and Guardians

by Marc Nieper-Wißkirchen

status: draft (2021-09-11)

keywords: Garbage Collection

See also SRFI 124: Ephemerons and SRFI 246: Guardians.

Abstract

Guardians allow programs to protect objects from deallocation by the garbage collector and to determine which objects would otherwise have been deallocated. When the object has associated non-memory resources, a program can register it with a guardian. The GC will mark inaccessible objects but will not collect them; at the program's convenience, inaccessible objects are removed from the guardian and their non-memory resources are disposed of. Guardians allow objects to be saved from deallocation indefinitely so that they can be reused or so that clean-up or other actions can be performed using the data stored within the objects. Guardians avoid the problems associated with classical finalizers detailed in the Rationale section.