Why I want Haskell finalizers
Alastair Reid
alastair at reid-consulting-uk.ltd.uk
Wed Oct 16 12:36:35 EDT 2002
George writes:
> 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.
So what you want is for the Java GC to call hs_freeStablePtr on all the
Haskell objects that just died?
That requires that the Haskell runtime system export a C function
hs_freeStablePtr which fiddles around with the relevant GC data
structure for stable pointers. No problem at all. Hugs has exported
this function for some years now (though under a slightly different
name).
Similarily, you want Haskell's GC to call a function in the Java
Native Interface (JNI) to release any Java objects that Haskell may
have. I imagine that is straightforward.
--
Alastair
More information about the FFI
mailing list