Why I want Haskell finalizers
George Russell
ger at tzi.de
Wed Oct 16 12:43:24 EDT 2002
Alastair Reid wrote:
>
> 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?
No, that's only a partial (and indeed very incomplete) solution. It relies on
the Java GC knowing that that particular reference to the Haskell StablePtr
is the only one that matters, and vice-versa for the Haskell GC. If you want any
slightly more complicated logic (such as if Java has multiple references to
the same StablePtr, or if you want to detect if this particular freeStablePtr
might free a circular data structure) you'll have to write it in C.
More information about the FFI
mailing list