System.Mem.Weak semantics question

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? Thanks in advance and best regards, Andrei Paskevich [1] http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.h...

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'. Cheers, Simon
participants (2)
-
Andrei Paskevich
-
Simon Marlow