On Sat, Jan 10, 2015 at 9:01 PM, <t...@wakelift.de> wrote: > > On 01/10/2015 07:53 PM, Gabor Szabo wrote: > > On Sat, Jan 10, 2015 at 7:57 PM, <t...@wakelift.de> wrote: > >> That happens because the result of the for statement is a list that is >> then sunk; it contains one scalar and one Int object for each iteration >> and rakudo doesn't yet know to throw it away immediately. >> > > The problem happens even without the internal $x variable, but my main > problem > is that this means the web application running the Perl6Maven.com site > fills the memory > after just a few requests. > > A quick check seems to indicated that while-loops don't have the same > memory leak, > but before I run and rewrite every for loop into a while-loop, it would be > nice to know > if there are other parts of the language that are leaking memory? > > > regards > Gabor > > > Fortunately, it's not as bad as you think. Compare these two invocations: > > time perl6 -e 'for ^1000 { for ^1000 { }; 1 }' > 0.91user 0.02system 0:00.94elapsed 99%CPU (0avgtext+0avgdata > 113448maxresident)k > > time perl6 -e 'for ^1000 { for ^10000 { }; 1 }' > 5.53user 0.02system 0:05.59elapsed 99%CPU (0avgtext+0avgdata > 114744maxresident)k > > > The MaxRSS hardly differs, because the list that belongs to the inner for > loop gets garbage collected properly. > > There isn't an actual memory leak, it's just that the result of the for > loop is (wrongly) being kept around. > > There was also an optimization that turns a for ^1000 loop into a while > loop with a native counter for great performance improvements, but that got > b0rked at some point ;( > > regards > - Timo >
Well, whatever it is, this means that the web application fills all the memory and crashes every 30-40 requests. Luckily there are not many people who read the site :) Gabor