GHC garbage collector

Simon Marlow simonmar@microsoft.com
Mon, 26 Nov 2001 09:46:38 -0000


> I have some code that uses FFI capabilities to associate=20
> previously allocated
> memory with a structure akin to a ByteArray and allows=20
> Haskell land to read
> and write to the C side of things.
>=20
> I use ForeignPtr and associate a destructor to allow the GHC's garbage
> collector to clean up after it figures out that the structure=20
> is no longer
> being used. I know I am in funny territory.
>=20
> In some instances (when benchmarking) GHC takes its time=20
> getting around to
> garbage collecting. Can someone suggest hooks to encourage=20
> GHC to clean up
> things? Or better still functions to instruct GHC to garbage=20
> collect specific
> structures (by calling relevant destructors)? Also comments=20
> 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