[Haskell-cafe] ForeignPtr and Garbage Collection

Matt Cox matt at mattcox.ca
Tue Jul 30 20:16:12 CEST 2013

The pointer held in a ForeignPtr is not managed at all by the GC. The
ForeignPtr itself is a GC'd object and runs a finalizer (a function
receiving a pointer) with the value it holds when it is destroyed.

For example, if you allocate a C resource in one foreign call and then
store its value in a foreign pointer, that externally allocated memory it
points to is outside the management of the GC.


On Tue, Jul 30, 2013 at 9:50 AM, satvik chauhan <mystic.satvik at gmail.com>wrote:

> Hi Cafe,
> Is it guaranteed that the value of `ForeignPtr` will not be changed (for
> example due to compaction etc) by haskell garbage collector until it goes
> out of scope and finalizer is run.
> -Satvik
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130730/425c69b2/attachment.htm>

More information about the Haskell-Cafe mailing list