Node:Guardians, Previous:Weak References, Up:Memory Management

29.3 Guardians

make-guardian [greedy?] Scheme Procedure
scm_make_guardian (greedy_p) C Function
Create a new guardian. A guardian protects a set of objects from garbage collection, allowing a program to apply cleanup or other actions.

make-guardian returns a procedure representing the guardian. Calling the guardian procedure with an argument adds the argument to the guardian's set of protected objects. Calling the guardian procedure without an argument returns one of the protected objects which are ready for garbage collection, or #f if no such object is available. Objects which are returned in this way are removed from the guardian.

make-guardian takes one optional argument that says whether the new guardian should be greedy or sharing. If there is any chance that any object protected by the guardian may be resurrected, then you should make the guardian greedy (this is the default).

See R. Kent Dybvig, Carl Bruggeman, and David Eby (1993) "Guardians in a Generation-Based Garbage Collector". ACM SIGPLAN Conference on Programming Language Design and Implementation, June 1993.

(the semantics are slightly different at this point, but the paper still (mostly) accurately describes the interface).

destroy-guardian! guardian Scheme Procedure
scm_destroy_guardian_x (guardian) C Function
Destroys guardian, by making it impossible to put any more objects in it or get any objects from it. It also unguards any objects guarded by guardian.

guardian-greedy? guardian Scheme Procedure
scm_guardian_greedy_p (guardian) C Function
Return #t if guardian is a greedy guardian, otherwise #f.

guardian-destroyed? guardian Scheme Procedure
scm_guardian_destroyed_p (guardian) C Function
Return #t if guardian has been destroyed, otherwise #f.