#447 closed defect (fixed)
Inconsistency when calling set-finalizer! multiple times on the same object
Reported by: | Moritz Heidkamp | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 4.9.0 |
Component: | unknown | Version: | 4.6.x |
Keywords: | Cc: | ||
Estimated difficulty: |
Description
The following program prints "b" when interpreted and "ba" when compiled:
(define x (list 1)) (set-finalizer! x (lambda (x) (display 'a))) (set-finalizer! x (lambda (x) (display 'b))) (set! x #f)
I am not sure whether replacing the existing finalizer or appending another finalizer makes more sense. However, it would probably be better if both cases behaved the same.
Change History (5)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
This should be fixed now (experimental). The code that walked the finalizer list checks for a finalized object being not forwarded into the new heap area on GC. Previously it marked the object, hiding the "non-forwarded" status for later finalizers for the same object in the finalizer list, which would then never be run. The list is now walked twice, once for checking, and once for marking. GC frequency and the location of objects in memory influence strongly how and when finalizers are checked and executed.
I have tried to improve the documentation.
comment:3 Changed 14 years ago by
Works like a charm, thanks a lot :-) The docs are clear to me now!
Weird. I increased your finalizers to 3 and added a (gc #t) to the end as well. Both cases look like they are behaving strangely.
Compiled:
Interpreted (csi -script):