Developers, Developers, Developers! Maksim Sorokin IT Blog


Memory Leak in Haskell During File Read 3

Problem described in previous two posts (1 2) has finally been fully understood and solved. Guys from #haskell channel on freenode IRC servers pointed me to the problem.

The thing is that in the memory leak example I took length of read file and appended it to accumulator, which was sent further in the tail call. And this accumulator was evaluated lazily! After adding strict sequencing operator, the memory leak gone.

So instead of tail call:

test fns $ acc + (B.length contents)

I should have used:

test fns $! acc + (B.length contents)
Comments (0) Trackbacks (2)

Leave a comment