[Haskell-cafe] About pointer taken by C lib in FFI.

Sylvain Henry sylvain at haskus.fr
Sun Jan 13 22:58:33 UTC 2019


Hi,

Ptr has no finalizer: you have to explicitly free the attached memory if 
necessary.

You can use ForeignPtr to associate finalizers to a pointer: finalizers 
are functions that are called when the ForeignPtr object is to be 
collected by the GC. GHC can't track if the pointer is still stored/used 
by the C lib though.

Hope that helps,
Sylvain


On 12/01/2019 07:16, Magicloud Magiclouds wrote:
> Hi,
>
> Say I have some data, and `poke` into a Ptr. Then I pass the Ptr to
> some function in C lib. The C lib stores the Ptr somewhere to use
> later.
>
> My question is, how does GHC handle the finalizing of the Ptr? Does it
> track the "used by foreign lib"?
>


More information about the Haskell-Cafe mailing list