ForeignPtr and -threaded

PHO phonohawk at
Sun Jul 22 22:07:40 EDT 2007

From: Bulat Ziganshin <bulat.ziganshin at>
Subject: Re: ForeignPtr and -threaded
Date: Sun, 22 Jul 2007 17:48:05 +0400

> try to add performGC at end - this should force collecting garbage and
> therefore printing of string. otherwise, it's ok - there is no guarantee
> that GC will be performed and therefore that you finalizer will be
> performed. it's rather stanard behavior for GC languages - finalizers
> are almosr useless there

So I changed the code like this but the result was exactly the
same. The documentations of both Foreign.ForeignPtr (*1) and
Foreign.Concurrent (*2) say "The only guarantee is that the finalizer
runs before the program terminates." So I expected the finalizer to be

import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.ForeignPtr
import System.Mem
import qualified Foreign.Concurrent as Conc

main = work >> performGC
      work = do mem  <- mallocBytes 10
                Conc.newForeignPtr mem $ print "called"


 - PHO -                
OpenPGP public key: 1024D/1A86EF72
Fpr: 5F3E 5B5F 535C CE27 8254  4D1A 14E7 9CA7 1A86 EF72
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url :

More information about the Glasgow-haskell-users mailing list