[Haskell-cafe] Re: space leak with 'concat' ?
bugfact at gmail.com
Thu Feb 12 05:22:35 EST 2009
On Thu, Feb 12, 2009 at 10:48 AM, Svein Ove Aas <svein.ove at aas.no> wrote:
> Using this as a guide, I tested these two programs:
> str = concat $ repeat "foo "
> main1 = print foo
> main2 = print foo >> print foo
> As I'm sure you realize, the first ran in constant memory; the second,
> not so much. Very interesting.
That seems logical to me. The first one prints the str once, and str is
never needed anymore. The second one prints str, and after it is printed, it
prints it again, so the full str is needed again. So the "life data"
analyzer is not clever enough to realize that the second print will never
occur. Solving the latter might require solving the halting problem? I don't
It is funny that recently I had a strange problem in C# (I tried to write
parts of Reactive in C#) where the garbage collector freed data that was
actually needed by my program! I had to fix that by putting a local variable
on the stack, passing the constructed data to a function did not work. I
think .NET and Java the garbage collector traverses from data (the stack,
globals, etc). If I understood Simon correctly, GHC traverse the code blocks
instead, which feels correct as it would have fixed the bug I had in C#. So
yet again an extreme difference between Haskell and .NET/Java even when it
comes to garbage collection, Haskell wins :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe