[Haskell-cafe] puzzling memory leak? (GHC)

Ben Lippmeier Ben.Lippmeier at anu.edu.au
Mon Oct 10 02:32:56 EDT 2005


Young,
This sounds like a text-book space-leak caused by lazy evaluation.

In a lazy language, function evaluation is driven by the need to perform 
IO. Because the first version of your program never prints the parsed 
structure, the parser doesn't completely parse it. This implies that the 
system needs to hang onto all the input data (as well as all the 
partially evaluated calls to the parser) incase it needs it later on.

The default string representation is Haskell is pretty abysmal, and 
having it use hundreds of megs to represent, say a 10 meg file is not 
too surprising.

By modifying your fixArts function to print the parsed structure you've 
forced the system to actually finish evaluating the parser, which allows 
the input data to be garbage collected.

My advice is that if you don't want to fool around with it, just swallow 
hard, then change fixArts to do a hPutArts to /dev/null.

Either that or
   1) go read about the DeepSeq library.
   2) add strictness annotations to your structure definition.

Ben.

> 
> fixArts ((Right x):xs) = do hPutArts stderr x
>                             fixArts xs
> 


More information about the Haskell-Cafe mailing list