Next: cancel-finalization, Up: Finalizers
The function finalize
pushes function to object's
list of finalizers, which will be invoked when object is
garbage-collected.
function should take no arguments.
For portability reasons, function should not attempt to look at object by closing over it because, in some lisps, object will already have been garbage-collected and is therefore not accessible when function is invoked.
(defclass wrapper-object () ...) (defmethod initialize-instance :after ((self wrapper-object) &key) (let ((foreign-pointer ...)) ... (finalize self (lambda () (foreign-free foreign-pointer)))))