
I have some code that uses FFI capabilities to associate previously allocated memory with a structure akin to a ByteArray and allows Haskell land to read and write to the C side of things.
I use ForeignPtr and associate a destructor to allow the GHC's garbage collector to clean up after it figures out that the structure is no longer being used. I know I am in funny territory.
In some instances (when benchmarking) GHC takes its time getting around to garbage collecting. Can someone suggest hooks to encourage GHC to clean up things? Or better still functions to instruct GHC to garbage collect specific structures (by calling relevant destructors)? Also comments on how safe this whole business is.
IOExts.performGC will cause a full garbage collection to be performed. If you want to be sure the finalizer has run to completion, you'll need to set up some synchronisation between the main thread and the finalizer using MVars. Finalizers have no special scheduling properties; they just run concurrently with the other threads in the system. Cheers, Simon
participants (1)
-
Simon Marlow