next up previous contents
Next: 2.6 Describe Up: 2.5 Garbage Collection Previous: 2.5.2 Weak Pointers

2.5.3 Finalization

Finalization provides a ``hook'' that is triggered when the garbage collector reclaims an object. It is usually used to recover non-Lisp resources that were allocated to implement the finalized Lisp object. For example, when a unix file-descriptor stream is collected, finalization is used to close the underlying file descriptor.

[Function]
extensions:finalize object function

This function registers object for finalization. function is called with no arguments when object is reclaimed. Normally function will be a closure over the underlying state that needs to be freed, e.g. the unix file descriptor in the fd-stream case. Note that function must not close over object itself, as this prevents the object from ever becoming garbage.

[Function]
extensions:cancel-finalization object

This function cancel any finalization request for object.



Raymond Toy
Mon Jul 14 09:11:27 EDT 1997