racket/collects/math/tests/strictness-memory-leak-test.rkt
Neil Toronto 8f17913d55 Fixed memory leak in making arrays strict: doing so wouldn't clear
the reference to the original procedure, which itself could hold on
to a lot of memory
2012-12-02 22:21:28 -07:00

17 lines
543 B
Racket

#lang racket
(require math/array
rackunit)
;; Make a procedure that returns a random value to keep the optimizer from converting it to a
;; top-level, non-closure; if that happens, the module keeps a reference to it, which makes this
;; test always fail
(define bx (make-weak-box (let ([v (random)]) (λ (js) v))))
(define arr (build-array #() (weak-box-value bx)))
;; Making `arr' strict should release the only remaining reference to the contents of `bx'
(array-strict! arr)
(collect-garbage)
(check-false (weak-box-value bx))