<br><br><div class="gmail_quote">On Wed, Dec 1, 2010 at 6:23 AM, Dmitry Kulagin <span dir="ltr">&lt;<a href="mailto:dmitry.kulagin@gmail.com">dmitry.kulagin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
I have problems with memory leaks and can&#39;t find out how to avoid them.<br>
I tried to reduce sample to demonstrate the following problems:<br>
1) when compiled without -O2 option, it iconsumes 1582MB (!) total memory<br>
2) when compiled with -O2 option it terminates with &quot;out of memory&quot;<br>
<br>
Actually I don&#39;t understand the reasons, particulary why  GC can&#39;t<br>
collect already processed objects g,...,n (see code below)?<br>
<br>
I would appreciate very much any help with this situation.<br>
Thanks!<br>
<br>
<br>
module Main where<br>
<br>
import qualified Data.Map as M<br>
<br>
len = 15*1024*1024<br>
lst from = take len $ zip [from..] [0..]<br>
<br>
g = M.size $ M.fromList $ lst 0<br>
h = M.size $ M.fromList $ lst 0<br>
i = M.size $ M.fromList $ lst 0<br>
j = M.size $ M.fromList $ lst 0<br>
k = M.size $ M.fromList $ lst 0<br>
l = M.size $ M.fromList $ lst 0<br>
m = M.size $ M.fromList $ lst 0<br>
n = M.size $ M.fromList $ lst 0<br>
<br>
main = do<br>
    mapM_ print [g,h,i,j,k,l,m,n]<br></blockquote><div><br></div><div>I&#39;m using ghc7 here.  If I run your program with -O2, it takes 1943 MB of memory max.</div><div><br></div><div>If I comment out everything except g and h then with -O2 it takes 1521 MB.</div>
<div><br></div><div>If I comment out everything except g then with -O2 it takes 1521 MB.</div><div><br></div><div>I&#39;m not sure where the extra 400 MB of memory are going.</div><div><br></div><div>When I compile with: -fno-cse -fno-full-laziness and -O2, the memory usage (with g though n) is 1585 MB.</div>
<div><br></div><div>Jason</div></div>