All Manuals > LispWorks® User Guide and Reference Manual > 37 The HCL Package

add-special-free-action Function

Summary

Adds a function to perform a special action during garbage collection.

Package

hcl

Signature

add-special-free-action function => function-list

Arguments
function
A function designator for a function of one argument.
Values
function-list
A list of the functions currently called to perform special actions, including the one just added.
Description

When some objects are garbage collected, you may require a "special action" to be performed as well. The function add-special-free-action adds the function function to perform the special action. Note that the function is applied to all objects flagged for special-free-action, so the function function should check for the object's type, so that it only affects relevant objects. Also, it should be fast when called with other objects.

The functions flag-special-free-action and flag-not-special-free-action flag and unflag objects for action.

When function is called, the object is still alive but is no longer flagged for special free action. Normally, the object will be collected on the next garbage collection cycle, but you can also store it somewhere which will prevent this. It may even be passed to flag-special-free-action again.

Notes

You should not rely on special free actions for objects with a high turn-over rate (that is, where many such objects are allocated and they become garbage fairly quickly), because some may not get collected early enough. Either ensure that the cleanup is called elsewhere, or arrange for a GC to happen.

Examples
(defun free-my-app (object)
  (when (my-app-p object)
    (free-some-external-resources object)))
 
(add-special-free-action 'free-my-app)
See also

remove-special-free-action
flag-special-free-action
flag-not-special-free-action


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:35