garbage collector killed? pasted by megane on Wed May 30 14:57:15 2012

(define n 2000)

(handle-exceptions
    exn
  (begin
    (print "Caught an exception" exn))
  (let loop [(i 0)]
    (let [(o (make-vector 100000))]
      (if (not (= i 1000))
	  (set-finalizer! o
			  (lambda (ob)
			    (print "gc'ing " i)))
	  (set-finalizer! o
			  (lambda (ob) (+ i 'a))))
      (if (< i n)
	  (loop (+ 1 i))))))
(print "making more objects")
(let loop [(i 0)]
  (let [(o (make-vector 100000))]
    (print i)
    (set-finalizer! o
		    (lambda (ob) (print "gc'ing 2 " i)))
    (if (< i n)
	(loop (+ 1 i)))))
(print "done")

;; Result when compiled:

;; [panic] out of memory - cannot allocate heap segment - execution terminated

;; OR

;; 100% cpu with no apparent progress

no title added by megane on Wed May 30 15:19:24 2012

...
679
680
[GC] 2 finalized item(s) still pending
[GC] 2680 finalizer value(s) marked
[GC] level  1	gcs(minor)  379	gcs(major)  22
[GC] stack	0xbfdc4a80	0xbfe03c00	0xbfe04a80
[GC]  from	0x77419008	0xb735f744	0xb7419000	0x3ff4673c
[GC]    to	0x09163008	0x09163008	0x49163000 
[GC] 0 locatives (from 32)
681
[GC] 2 finalized item(s) still pending
[GC] 2681 finalizer value(s) marked
[GC] level  1	gcs(minor)  0	gcs(major)  23
[GC] stack	0xbfdc4a80	0xbfe03c00	0xbfe04a80
[GC]  from	0x09163008	0x4910b1d8	0x49163000	0x3ffa81d0
[GC]    to	0x77419008	0x77419008	0xb7419000 
[GC] 0 locatives (from 32)