[Ecls-list] Troubles with finalization
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Tue Oct 10 15:17:50 UTC 2006
Hi,
I have also fixed a problem with finalization. It is was a nasty
little bug: when an object with some finalization code is marked as
unreachable it has to be pushed to a list of calls to be performed.
Well, it turns out that pushing into the list caused some small amount
of memory to be allocated which in turn caused the garbage collector
to be called and other finalization routines to be invoked, so that
the whole list of to-be-finalized calls was lost.
Those interested in the details can look at src/c/alloc_2.d
Now it seems to work
---- example.lsp ----
(defun custom-finalizer (tag)
#'(lambda (object)
(format t "~%Finalizing ~A" tag)))
(let ((a (cons 1 1)))
(si::set-finalizer a (custom-finalizer 1)))
(let ((b (cons 1 1)))
(si::set-finalizer b (custom-finalizer 2)))
(dotimes (j 100)
(dotimes (i 10000)
(cons 1.0 1.0))
(si::gc t))
--- session ---
> (load "example")
;;; Loading #P"/home/jlr/src/ecls-new/build/example.lsp"
Finalizing 1
Finalizing 2
--- the current test ---
(deftest cl-0009-finalization
(let ((*all-tags* '()))
(declare (special *all-tags*))
(flet ((custom-finalizer (tag)
#'(lambda (o) (push tag *all-tags*))))
(let ((a '()))
(dotimes (i 5)
(let ((x (cons i i)))
(si::set-finalizer x (custom-finalizer i))
(push x a))))
(dotimes (j 100)
(dotimes (i 10000)
(cons 1.0 1.0))
(si::gc t)))
(sort *all-tags*))
(0 1 2 3 4))
More information about the ecl-devel
mailing list