Hello,
I found myself wanting to reference the finalized object from a finalizer, so I added this wrapper around trivial-garbage:finalize, using a weak pointer to avoid permanently referencing the object from the finalizer closure.
(defun add-finalizer (x f) (setf p (make-weak-pointer x)) (setf g (lambda () (funcall f (weak-pointer-value p)))) (finalize x g))
Would there be any problems with adding this function to the main library? I could probably provide a patch if requested.
Best regards, Hans
On Sat, Dec 8, 2012 at 10:57 PM, Hans Höglund hans@hanshoglund.se wrote:
I found myself wanting to reference the finalized object from a finalizer, so I added this wrapper around trivial-garbage:finalize, using a weak pointer to avoid permanently referencing the object from the finalizer closure.
Which Lisp are you using. IIRC, some (most?) Lisps run finalizers /after/ the object's memory is reclaimed, in which case the weak pointer will be null.
trivial-garbage-devel@common-lisp.net