[racket-dev] [plt] Push #25886: master branch updated

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Dec 11 13:46:08 EST 2012

At Tue, 11 Dec 2012 11:36:22 -0700, Neil Toronto wrote:
> >   (define mpfr-shutdown
> > -  (register-custodian-shutdown mpfr-free-cache (λ (free) (free))))
> > +  (register-custodian-shutdown
> > +   mpfr-free-cache ; acts as a "random" object for a shutdown handle
> > +   (λ (free)
> > +      ;; The direct reference here is important, since custodian holds only
> > +      ;; a weak reference to shutdown handle:
> > +      (mpfr-free-cache))))
> 
> Is the problem here that `free' may point to an object that has been 
> collected, or may be #f because the object has been collected?

The `free' object won't have been collected, but it may have been
finalized, since the reference from the custodian is weak. In
particular, foreign functions are finalized.

> If so, then the callback procedure can't rely on the value of `free' 
> unless it contains its own reference to `free'. So why pass it? 

In a more typical case, the value registered with a custodian is not
finalized. Or maybe it can be finalized, but the custodian callback for
the value can deal with a finalized value (and do nothing in that case,
typically).

> Also, 
> why doesn't the module's reference to `mpfr-free-cache' count? Because 
> the module may have been collected already?

Yes, the module may be long gone.



Posted on the dev mailing list.