[Haskell-cafe] Memory Leak Help

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Mon Nov 12 02:31:20 EST 2007

J. Garrett Morris wrote:
> Hello,
> I have code which seems to contain a memory leak, but I'm not sure
> where it is or what's causing it.  Any help would be greatly
> appreciated:

I see no memory leak in your code, it "just" breaks the garbage
collector's heuristics by allocating an awful lot of data at once and
then using no more memory.

Try running your program with  +RTS -F1.1 -RTS. (The -F option controls
by how much the RTS increases the heap size when the heap gets exhausted.
The default is to double it, but for this program a modest increment is
much more sensible).

> data Ratings = Ratings { movieCount :: Int
>                        , movieLookup :: IOUArray Int Word32
>                        , movieRatings :: IOUArray Word32 Word32 }
>               | otherwise = do writeArray movieRatings i rating    -- ***

Btw, my first instinct was to suggest using ... $! rating  here, but with
unboxed arrays that's not necessary.


Hope that helps,


More information about the Haskell-Cafe mailing list