[Haskell-cafe] How to check for memory leak.

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Sun Feb 12 05:02:32 EST 2006

zbo <ed_duh at hotmail.com> writes:

> I dont know whether this is a memory leak or just the GC not collecting yet. 
> I was just wondering What is the general method to check this.
> BTW, I have tried using -prof and -P, but not really able to see anything
> suspicious.

You want to use heap profiling, not time profiling.

  * Compile with -prof -auto-all.
  * Run with +RTS -hc -RTS.
       (or perhaps various other options all beginning -h)
  * Convert the resulting .hp file to postcript using hp2ps.
  * View the postscript diagram.
  * If there is a ramp that grows and never drops, there is a
    persistent space leak.  On the other hand, large spikes can
    also be a space problem.  The ideal shape is mostly-flat.

See the ghc users guide sections 5.4 and 5.6.  For papers about how to
interpret profile graphs, try (for instance)

  C.Runciman and D.Wakeling. Heap profiling of lazy functional programs.
  Journal of Functional Programming, 3(2):217-245, 1993.

  C.Runciman and N.Rojemo. New dimensions in heap profiling. Journal of
  Functional Programming, 6(4):587-620, 1996.


More information about the Haskell-Cafe mailing list