Elise,

I remember that your earlier email on the beginner list asked about "diffing from moment to moment." Perhaps you can sketch what you're trying to achieve?

Because once you get into the internals of GC the learning ramp gets very, very steep. There are traps known and unknown for both the wary and unwary, as a cursory overview of GHC trac will inform.

There's probably a way of getting things to work without relying on implementation-specific haskell.

-- Kim-Ee

On Mon, Jan 19, 2015 at 7:10 PM, Elise Huard <haskell@elisehuard.be> wrote:
Hi,

I was wondering if there was a way to check whether a particular data
structure gets garbage collected in a program.  A friendly person
pointed me to System.Mem.Weak on the Haskell-Beginner list - however
I've been unable to verify how it works, so I'm bumping it to this
list.

See the following toy program: I was trying to see whether the output
would contain "garbage collected".
I wondered if performGC is a nudge rather than an immediate "garbage
collect now" instruction, and performGC is not actually performed?  Or I've
misunderstood finalizers in this context and they would not actually
be executed when z gets garbage collected?

import System.Mem.Weak
import System.Mem (performGC)
import Control.Concurrent (threadDelay)


main :: IO ()
main = do let x = 5
              y = "done"
              z = 3
          a <- mkWeak z x (Just (putStrLn "garbage collected"))
          performGC
          threadDelay 20000000
          print y

Thank you,

Elise
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe