FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 9.0
This page is new in 9.0.


Arguments: finalizer

If a finalization is scheduled with schedule-finalization with the queue argument non-nil (which must be a queue), then when the object associated with the finalization is marked as garbage, the system puts a finalization object on the queue specified by the queue argument (and takes no further action).

The program must then deal with the finalization object by applying this function to it. The finalization object is a list of the finalization function and the object. call-finalizer calls the finalization function and ensures that the object is marked as garbage (unless the finalization function did something to make the object not garbage), just as the system would do if the finalization was scheduled with queue nil.


;; We create a queue object:

cl-user(2): (setq queue (make-instance 'mp:queue))
#<multiprocessing:queue @ #x20c4641a>

;; We will add a non-queued finalization to this object:
cl-user(3): (setq aa (make-array 4))
#(nil nil nil nil)
cl-user(4): (defun foo (x) (format t "I, ~s, am garbage!!!" x))

;; Here we create the non-queued finalization:
cl-user(5): (schedule-finalization aa 'foo)
#(#(nil nil nil nil) foo nil)

;; We dereference it:
cl-user(6): (setq aa nil)

;; And it is run when the object is marked as garbage:
cl-user(7): (gc)
I, #(nil nil nil nil), am garbage!!!
cl-user(8): (gc)

;; A new object, which we will schedule a queued finalization:
cl-user(9): (setq bb (make-array 5))
#(nil nil nil nil nil)

;; We schedule the finalization:
cl-user(10): (schedule-finalization bb 'foo :queue queue)
#(#(nil nil nil nil nil) (#<multiprocessing:queue @ #x2097b332> . foo) nil)

;; We dereference the object:
cl-user(11): (setq bb nil)
cl-user(12): (gc)
cl-user(13): (gc)
cl-user(14): (gc)

;; Finalization is not run even after three gc's.

;; We run the finalization ourselves:
cl-user(15): (call-finalizer (mp:dequeue queue))
I, #(nil nil nil nil nil), am garbage!!!

Copyright (c) 1998-2012, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 9.0. This page is new in the 9.0 release.
Created 2010.1.21.

Allegro CL version 9.0
This page is new in 9.0.