[Haskell-cafe] FFI woes!
robdockins at fastmail.fm
Wed Dec 15 22:58:53 EST 2004
On Thu, 2004-12-16 at 01:05 +0100, Sebastian Sylvan wrote:
> Another question!
> Is there a way to force the garbage collector to kick in?
> I''m trying to find out if my finalizer gets called correctly but I
> don't know if the garbage collector is run.
I'm kind of surprised no one has yet mentioned this, so I will. Relying
on finalizers to perform significant clean up actions (ie, anything
besides memory deallocation) is rather frowned upon. I think that
spawing a thread and doing other heavy-duty actions inside a finalizer
is a bad idea, for several reasons:
1) Finalizers are not (some say cannot) be guaranteed to run, even on
normal program termination, even if you force GC before exiting.
2) Finalizers can run when the RTS is in a bizarre state (eg, STDOUT
might not be avaliable, because it has already been finalized)
3) Finalizers cannot be ordered (2 is a consequence of this)
4) Finalizers are run at unpredictable times.
I would suggest you find some way to accomplish what you want without
More information about the Haskell-Cafe