System.Mem.Weak semantics question

Simon Marlow marlowsd at
Fri Mar 25 17:48:03 CET 2011

On 01/03/2011 11:22, Andrei Paskevich wrote:
> Hello,
> The documentation page on System.Mem.Weak [1] contains the following
> sentence: "The finalizer, and the relationship between the key and the
> value, exist regardless of whether the program keeps a reference to
> the Weak object or not." Our reading of this statement implies, in
> particular, that,
> - given a key k, a value v, and a weak pointer w<- mkWeak k v Nothing,
> - if we lose all references to v and w,
> - then the value v will not be garbage-collected as long as we keep a
> reference to k, even though we cannot possibly retrieve v from k only.
> Is our understanding correct?

Yes (as we discussed offline, but for the benefit of the list): "mkWeak 
k v" adds a new edge to the reachability graph from k to v.  You can 
delete the edge with 'finalize w'.


More information about the Libraries mailing list