Finalizers and FFI

Alastair Reid alastair at
Thu Jun 10 06:22:37 EDT 2004

> [program deleted]
> So, this basically means that my finalizer did not get run :(
> [...]
> It should run, in separate thread or not, it doesn't matter here.
> Any ideas why doesn't it work?

Hopefully the GHC folk will correct me if I'm wrong but I think what happens 

- you allocate object with finalizer
- the object becomes inaccessible
- performGC causes the object to be freed by the garbage collector
- the garbage collector schedules a thread to run your finalizer


- before the finalizer thread has a chance to be scheduled, your
  program exits.

You could give the finalizer thread a chance to run by calling 
Control.Concurrent.yield before exiting:

That is, call yield just after calling performGC.

Alastair Reid

More information about the Glasgow-haskell-users mailing list