title: Haskell FFI: ForeignPtr seems not to get freed (maybe a GHC bug?)
body: <p>Consider the following code snippet</p>
  
  <pre><code>import qualified Foreign.Concurrent
  import Foreign.Ptr (nullPtr)
  
  main :: IO ()
  main = do
    putStrLn "start"
    a &lt;- Foreign.Concurrent.newForeignPtr nullPtr $
      putStrLn "a was deleted"
    putStrLn "end"
  </code></pre>
  
  <p>It produces the following output:</p>
  
  <pre><code>start
  end
  </code></pre>
  
  <p>I would had expected to see "<code>a was deleted</code>" somewhere after <code>start</code>..</p>
  
  <p>I don't know what's going on. I have a few guesses:</p>
  
  <ul>
  <li>The garbage collector doesn't collect remaining objects when the program finishes</li>
  <li><code>putStrLn</code> stops working after <code>main</code> finishes. (btw I tried same thing with foreignly imported <code>puts</code> and got the same results)</li>
  <li>My understanding of <code>ForeignPtr</code> is lacking</li>
  <li>GHC bug? (env: GHC 6.10.3, Intel Mac)</li>
  </ul>
  
  <p>When using <code>Foreign.ForeignPtr.newForeignPtr</code> instead of <code>Foreign.Concurrent.newForeignPtr</code> it seems to work:</p>
  
  <pre><code>{-# LANGUAGE ForeignFunctionInterface #-}
  
  import Foreign.C.String (CString, newCString)
  import Foreign.ForeignPtr (newForeignPtr)
  import Foreign.Ptr (FunPtr)
  
  foreign import ccall "&amp;puts" puts :: FunPtr (CString -&gt; IO ())
  
  main :: IO ()
  main = do
    putStrLn "start"
    message &lt;- newCString "a was \"deleted\""
    a &lt;- newForeignPtr puts message
    putStrLn "end"
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>start
  end
  a was "deleted"
  </code></pre>