20-gc-closure-churn.scm (680B)
1 ;; Closure churn: each call to make-counter evaluates a fresh 2 ;; (lambda () ...) which allocates a 32-byte closure object on the 3 ;; obj heap. The closure is consumed on the next line and becomes 4 ;; unreachable. Iterating exhausts the obj heap and forces GC to 5 ;; reclaim dead closures via the obj-arena sweep + free-list path. 6 ;; 7 ;; Each iteration drops 1 closure (32 bytes) plus a pile of 8 ;; transient pairs (eval_args, env-extend). 800 iterations easily 9 ;; cycle both arenas multiple times. 10 11 (define make-counter 12 (lambda (start) 13 (lambda () start))) 14 15 (define churn 16 (lambda (n) 17 (if (= n 0) 18 42 19 (begin ((make-counter n)) (churn (- n 1)))))) 20 21 (churn 800)