From: Bulat Ziganshin <[EMAIL PROTECTED]>
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
called.


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

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


*1: 
http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-ForeignPtr.html
*2: 
http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Concurrent.html

_______________________________________________________
 - PHO -                          http://ccm.sherry.jp/
OpenPGP public key: 1024D/1A86EF72
Fpr: 5F3E 5B5F 535C CE27 8254  4D1A 14E7 9CA7 1A86 EF72

Attachment: pgpr91nytJP5B.pgp
Description: PGP signature

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to