Weak reference semantics - why does a dead weak ref keep its value alive?

Luite Stegeman stegeman at gmail.com
Sat May 24 00:11:30 UTC 2014


>
>
> In particular, the variant of weak reference you suggest is the
> /ephemeron/ semantics in Hayes.  Their reachability rule is:
>
>     The value field of an ephemeron is reachable if both (a) the
>     ephemeron (weak pointer object) is reachable, and (b) the key is
>     reachable.
>
>
Actually it's not the same, since I think the finalizer should still be run
if the weak pointer object is unreachable (and it should run when the key
becomes unreachable).

The implementation would indeed need to keep some reference to the key and
finalizer around after the weak pointer becomes unreachable, perhaps on
some weak pointers list, but the same goes for GHC's semantics. The only
difference is that the value (which might in turn make a whole bunch of
other data reachable) would not have to be retained.

I haven't been able to think of any issues with considering the value
unreachable here, so I'm still puzzled as to why GHC's semantics would be
preferable. It doesn't look like it would complicate implementation too
much either.

luite
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20140524/2c79c5fc/attachment.html>


More information about the ghc-devs mailing list