Finalizers: conclusion?

John Meacham john at
Mon Oct 21 20:51:56 EDT 2002

I also need the touchForeignPtr trick in much of my code. we need to
come up with a replacement if we dont have haskell finalizers. here are
my canidate suggestions:

* add a subset of Weak pointers (or some subset of their functionality)
  to the FFI spec. just get rid of the finalizer capability (for obvious
  reasons) and the Weak pointers work just as well, and it might have uses

- or -

* add addForeignDependency :: ForeignPtr a -> ForeignPtr b -> IO ()
 (which on ghc is trivially implemented as 
  'addForeignDependency a b = mkWeak a b Nothing >> return ()')

note that breaking these dependencies might be tricky/impossible
depending on what we choose. with weak pointers, one can finalize the
Weak that the mkWeak call returns, but then you have to keep track of
them in a seperate data structure than your ForeignPtr, which doesnt
seem ideal. a better solution would be some sort of

breakWeakPtr :: k -> v -> IO () 
breakForeignDependency :: ForeignPtr a -> ForeignPtr b -> IO ()



On Mon, Oct 21, 2002 at 02:50:03PM -0400, Antony Courtney wrote:
> I have only been watching this Haskell finalizers discussion from a 
> great distance, but I am keenly interested in the outcome, as it will 
> require a significant overhaul of some of my own FFI-based library code. 
>  (My code currently uses touchForeignPtr in a Haskell finalizer to 
> express a liveness dependency, but this is apparently not supported by 
> the latest FFI spec. and won't be.)

John Meacham - California Institute of Technology, Alum. - john at

More information about the FFI mailing list