Why I want Haskell finalizers

George Russell ger at tzi.de
Wed Oct 16 11:19:10 EDT 2002


The document which Simon and Alastair have kindly put together asks for more details
about why I want foreign garbage collectors to be able to call back to Haskell.  Well
I can't supply many details, because this is not immediately required by the UniForM/MMiSS
project we are working on at Bremen.  However the problem is a fairly simple and general
one.  If you have Haskell talking to some other language with a garbage collector, be
it Java or SML, then at a given point of the program you can in general expect to
have Haskell holding stable pointers to objects referenced from their world by the other language,
and vice-versa.  The most obvious way of garbage-collecting these is for each language to
reference the foreign objects using its own version of ForeignPtr's, which then instruct
the other's RTS that the corresponding stable pointer is no longer required.  This mechanism does
not handle circular pointers (Haskell references an ML object, which in turn references the
original Haskell object again) but it is at least a start.  Furthermore as a programmer I think
my response to circular dependencies would be to try to avoid them, for example by breaking
cycles by making some of the links weak, since a general solution would be fairly complex.
I think in any case a general solution would very probably use finalizers to handle finalizers,
while doing some complex pointer-chasing to detect and break cycles.



More information about the FFI mailing list