> On Fri, Apr 5, 2013 at 8:22 PM, Jerrad Pierce <[email protected]> wrote:
> >>at each level of recursion. What seems to be the case though is that when 
> >>we start going bac
> >>up the stack that memory doesn't seem to be released at each pop. If, say, 
> >>at max depth
> >>500mb of ram has been allocated I don't see that released at any point 
> >>except for when
> >>perl exits and then of course it is all released at once. Or at least that 
> >>is what
> >>seems to happen.
> >
> > Perl doesn't release memory, it keeps it for reallocation.
> > This is (was?) one of the issues one had to be aware of with mod_perl.
> 
> Normally the memory is not given back, but Perl does make a good faith
> effort to try to give it back if it is convenient.
> http://www.perlmonks.org/?node_id=746953 has a couple of examples of
> where it can happen.
> 
> However this is not an issue in practice very often.

After making sure the recursive implementation was correct I re-did it 
iteratively and did some comparisons
with Benchmark.
As expected the recursive implementation was slower:
(output from cmpthese())
recursive   6.98        --      -42%
iterative   4.04       73%        --
more amusing though was the memory usage. 
Looking at the RSS values for the perl process the iterative solution used ~9MB 
of RAM and the recursive solution came in at about 350MB. This was for a 
recursive depth of 4000 which represents a very large, but not wholly 
unreasonable, input.

                                          

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to