The current behaviour of finalizers in GHC is a bit strange:
-- Strange.hs --------------------------------------------------------
import Foreign
import System.Environment
useMem :: IO ()
useMem = if length (fib 27) == 0 then return () else return ()
where fib :: Int -> [Int]
fib 0 = [1]
fib 1 = [1]
fib n = fib (n-1) ++ fib (n-2)
main :: IO ()
main = do
args <- getArgs
ptr <- malloc
newForeignPtr (ptr :: Ptr Int32) (putStrLn "Finalising...")
case args of
["1"] -> return ()
["2"] -> putStrLn "Created"
["3"] -> do useMem ; putStrLn "Created"
_ -> putStrLn "unknown test"
----------------------------------------------------------------------
panne@jeanluc:~> ghc -O -Wall -o Strange Strange.hs
panne@jeanluc:~> ./Strange 1
Finalising...
panne@jeanluc:~> ./Strange 2
Created
panne@jeanluc:~> ./Strange 3
Finalising...
Created
----------------------------------------------------------------------
The first and third runs are fine, but why is the finalizer not invoked
on the second run?
The thing I wanted to check in the first place was: Are foreign objects
really kept alive if they can only be reached via a callback made with
'foreign import "wrapper"'? They definitely should be, but I couldn't
verify this, given the current state of affairs... :-(
Cheers,
S.
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc