#5729: ForeignPtr leak in ghci
--------------------------+-------------------------------------------------
Reporter: judahj | Owner:
Type: bug | Status: new
Priority: normal | Component: GHCi
Version: 7.2.1 | Keywords:
Os: MacOS X | Architecture: x86_64 (amd64)
Failure: None/Unknown | Testcase:
Blockedby: | Blocking:
Related: |
--------------------------+-------------------------------------------------
I have a program which creates an infinite list of Storable Vectors and
then scans through the list until some condition has been met. When
compiled, the program runs in constant space. When run in ghci, however,
the program leaks memory.
I can reproduce the behavior with the following module, using both
`ghc-7.2.1` and `ghc-7.4.0.20111219` on Mac OS X 10.7 x86_64. More
precisely, I do not see a leak (using `top`) when the program is
- Compiled with `ghc --make -O2` and run from the command-line
- Compiled with `ghc --make -O0` and run from the command-line
- Compiled with `ghc --make -O0`, loaded into `ghci` and run with `:main`
But I do see a leak (`top` shows a growing memory usage) when the program
is
- Loaded uncompiled into `ghci` and run with `:main`
- Compiled with `ghc --make -O2` (or `-O`), loaded into `ghci` and run
with `:main`.
{{{
module Main where
import System.IO.Unsafe
import Foreign.ForeignPtr
import Control.Exception
main = do
let steps = infinite 256
evaluate $ myLast steps
myLast :: [a] -> a
myLast [x] = x
myLast (x:xs) = myLast xs
infinite :: Int -> [ForeignPtr ()]
infinite n = let
xs = makeVector n
in xs `seq` (xs : infinite n)
makeVector :: Int -> ForeignPtr ()
makeVector n = unsafePerformIO $ mallocForeignPtrBytes n
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5729>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs