source: project/chicken/branches/prerelease/tests/test-finalizers.scm @ 13414

Last change on this file since 13414 was 13414, checked in by felix winkelmann, 11 years ago

merged with trunk rev. 13389

File size: 832 bytes
Line 
1;;;; test-finalizers.scm
2
3(define x (list 1 2 3))
4(define y (list 4 5 6))
5(define x-f #f)
6(define y-f #f)
7
8(begin
9  (set-finalizer! 
10   x
11   (lambda (o)
12     (format #t "Delete: ~A (y: ~a)~%" o y-f)
13     (set! x-f #t)))
14  #t) 
15(begin
16  (set-finalizer! 
17   y 
18   (let ((p x))
19     (lambda (o)
20       (format #t "Delete: ~A: ~A~%" o p)
21       (set! y-f #t))))
22  #t)
23(gc #t)
24(assert (not x-f))
25
26#|
27
28This ought to work, see patches/finalizer.closures.diff for
29a fix that unfortunately disables finalizers in the interpreter
30(probably due to the different closure representation).
31
32(assert (not y-f))
33(set! x #f)
34(gc #t)
35(assert (not x-f))
36(assert (not y-f))
37(set! y #f)
38(gc #t)
39(assert y-f)
40(assert x-f)
41|#
42
43(define foo-f #f)
44
45(let ((foo (vector 1 2 3)))
46  (set-finalizer! foo (lambda _ (set! foo-f #t)))
47  #t)
48
49(gc #t)
50(assert foo-f)
Note: See TracBrowser for help on using the repository browser.