Next: , Up: Finalizers


finalize

Syntax

— Function: finalize object function => object

Arguments and Values

object
A Lisp object.
function
A Lisp function.

Description

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.

Examples

  (defclass wrapper-object ()
    ...)
   
  (defmethod initialize-instance :after ((self wrapper-object) &key)
    (let ((foreign-pointer ...))
      ...
      (finalize self (lambda () (foreign-free foreign-pointer)))))

See Also

cancel-finalization