[racket-dev] Testing whether a procedure gets collected

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sat Dec 1 21:07:19 EST 2012

On 12/01/2012 07:05 PM, Neil Toronto wrote:
> Ah. It prints #f for me when I have debugging info turned on in
> DrRacket; otherwise I get #<procedure>. Must be inlining keeping it
> around or something.
>
> The problem with either finalizers or weak boxes is that neither
> provides enough guarantees. Finalizers are never guaranteed to be run. A
> weak box may not be the only reference to a procedure value, depending
> on what optimizations are done. I'm trying to test something that's
> normally not supposed to be observable.
>
> [...]
>
> Maybe a weak box containing a random closure would work. Hmm...

This seems to evaluate to #f under all circumstances:

#lang racket

(define (make-box-thing v)
   (make-weak-box (λ (_) v)))

(define bx (make-box-thing (random)))
(collect-garbage)
(weak-box-value bx)


I can't think of a way the optimizer could defeat that. It *has* to 
create a closure... right?

Neil ⊥


Posted on the dev mailing list.