
Hello PHO, Sunday, July 22, 2007, 5:36:27 PM, you wrote:
[2] Foreign.ForeignPtr
The following code prints nothing when it isn't linked with -threaded RTS, but when it is, it *sometimes* prints "called" but not always.
import Foreign.Marshal.Alloc import Foreign.Ptr import Foreign.ForeignPtr
foreign import ccall "wrapper" mkFinalizer :: (Ptr () -> IO ()) -> IO (FunPtr (Ptr () -> IO ()))
main = do mem <- mallocBytes 10 fin <- mkFinalizer $ \ _ -> print "called" newForeignPtr fin mem
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 -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com