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

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Oct 22 13:15:47 EDT 2006


Hello Udo,

Sunday, October 22, 2006, 6:41:24 PM, you wrote:

>> Now, the state will not be entirely consumed/evaluated by the user,
>> and so it will not become garbage. Am I right?

> No.  The state cannot become garbage, because there is still a reference
> to it.  As long as runStateT has not returned, any part of the state can
> still be accessed, so it is not garbage.

this monad state is not something fixed, it's completely replaced by
each setState call (and old state becomes garbage from this moment).
in particular, with this toy example, after reading each next file,
old file contents continue its life as garbage

> Completely evaluating the
> state will not reduce memory consumption in your case, because the list
> of lists won't be substantially smaller that the thunk to create it.  In
> fact, evaluating this thunk will consume memory.

while this is true for this particular data (i.e., getContents >>= lines)
in general this is not true. f.e. [[toUpper 'a']] list will need more
memory in unevaluated form

>  
>> Where should I force evaluation? 

> You can't.  Your state really is that large, at least in the toy
> example.  You'd need a different data structure ((Array Int ByteString)
> or (Map Int ByteString) come to mind) and then make that strict.

[ByteString] will be enough. Andrea, may be you can convert strings to
bytestrings after hxt conversion?



-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list