How about using a weak box instead? Robby
On Sat, Dec 1, 2012 at 11:45 AM, Neil Toronto <neil.toro...@gmail.com> wrote: > I'm getting ready to push a change to math/array that fixes a memory leak. > I've devised a test that I think will determine whether an array's procedure > gets collected after the array is made strict, but I don't know whether it > works only by accident. Here it is: > > > (define: collected? : (Boxof Boolean) (box #f)) > > (define arr > (let ([proc (λ: ([js : Indexes]) 0)]) ; constant array > (register-finalizer proc (λ (proc) (set-box! collected? #t))) > (build-array #() proc))) > > (array-strict! arr) > (collect-garbage) > (sleep 0) ; give finalizers a chance to run? > (check-true (unbox collected?)) > > > This test passes for me now, but will fail if anyone else tries it. What > worries me is that (sleep 0) is apparently required, meaning that finalizers > aren't run immediately when garbage is collected. > > How can I ensure that the finalizer for `proc' gets run before I test the > value of `collected?'? > > Neil ⊥ > _________________________ > Racket Developers list: > http://lists.racket-lang.org/dev _________________________ Racket Developers list: http://lists.racket-lang.org/dev