<p dir="ltr"><br>
On Jan 19, 2015 7:10 AM, "Elise Huard" <<a href="mailto:haskell@elisehuard.be">haskell@elisehuard.be</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I was wondering if there was a way to check whether a particular data<br>
> structure gets garbage collected in a program.  A friendly person<br>
> pointed me to System.Mem.Weak on the Haskell-Beginner list - however<br>
> I've been unable to verify how it works, so I'm bumping it to this<br>
> list.</p>
<p dir="ltr">Yes, sort of. You can use that to tell if a certain *constructor* has been collected, but that's not always so helpful. For instance, if you make a weak pointer to a list, and find that it's been collected, that just means the first (:) constructor has been collected. It may well be that the rest of the list spine and all its elements are still live. I ran into this problem trying to find out if an Array had been collected. It turned out that the Array constructor that holds the array bounds had been, but the actual Array# holding the elements was still around!</p>
<p dir="ltr">> See the following toy program: I was trying to see whether the output<br>
> would contain "garbage collected".</p>
<p dir="ltr">I'm not sure what the deal is there exactly, but my *guess* is that GHC may never actually bother allocating x or z at all. Finalizers are not guaranteed to ever run; they're a sort of "please, if you have the time" kind of thing.</p>
<p dir="ltr">> I wondered if performGC is a nudge rather than an immediate "garbage<br>
> collect now" instruction, and performGC is not actually performed?</p>
<p dir="ltr">No, I think that's a pretty definite "Do this now." I just think the garbage you *think* exists and the garbage that *actually* exists are probably different.</p>