[Haskell-cafe] memory, garbage collection and other newbie's issues

Udo Stenzel u.stenzel at web.de
Sat Oct 21 12:41:32 EDT 2006

Andrea Rossato wrote:
> I did not get an appreciable improvement with performGC, as you can
> see from here:
> http://gorgias.mine.nu/haskell/a.out.withPerformGC.ps
> But I found a solution: just write the opml state component to a file!

Obviously the values in question were not garbage, rather these were
unevaluated thunks.  Writing the data causes it to be evaluated, the
thunks become garbage and get collected.

The correct solution however, is the application of 'seq' at the right
places.  To understand where these are, perform a simulation of
Haskell's reduction strategy on paper.

> > second, each Char in ghc occupies 12 bytes (!)
> > 
> > multiplying this at 2.5 or even 3 factor which i described in previous
> > letter means, say, 30 mb used
> 30 Mega used for reading a feed is a number that I seem to get. 

Depends on what you're doing with the data.  If you scan a stream of
Chars exactly once, the space requirement per Char is next to
irrelevant.  If you're keeping lots of Strings around, using
PackedStrings will help (and be sure to pack strictly).  But I actually
suspect, you are running a backtracking parser over your input, so the
whole input is read into a String and cannot be disposed of as long as
the parser might backtrack.  If this is Parsec, you need to remove a
redundant 'try'.  If it is the Read class, you need to replace it by
Parsec or ReadP...

<Lorien> Ich glaub vorher defragmentier ich meine Festplatte, schmeiß
    alle CDs weg und installier Löwenzahn, Teletubbies, Pokemon usw. auf
    meinem Rechner. Dann lauf ich amok. Das wird den Psychologen EINIGES
    zu denken geben.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061021/da747fde/attachment.bin

More information about the Haskell-Cafe mailing list