
#10415: ForeignPtr touched in FFI wrapper is never discarded -------------------------------------+------------------------------------- Reporter: Deewiant | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: invalid | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Runtime | (amd64) performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * status: new => closed * resolution: => invalid Comment: The `FunPtr`s produced by a wrapper are like `Ptr`s, not `ForeignPtr`s. The functions they point to aren't and can't be managed by GC, because you can pass one directly to a C function and it can squirrel the pointer away in a C data structure somewhere. So the wrapped functions in this program live forever, and since they refer to the `ForeignPtr` `fp`, the memory managed by that pointer lives forever as well. You can free the result of a wrapper explicitly with [http://hackage.haskell.org/package/base-4.8.0.0/docs/Foreign- Ptr.html#v:freeHaskellFunPtr freeHaskellFunPtr]. If you add such a call to your program, say, after the `threadDelay`, then the 30 megabyte object does get freed. Please reopen if I am missing some subtlety here! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10415#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler