It's not only that Perl does not free the memory.

Many (all?) unix implementations can only grow the process user space, never shrink it. In fact, I think that Windows* works the same way...

This is one reason to design fork()ing servers. You can have a relatively small process waiting for requests and then fork() to serve each one. As the childs terminate, their whole memory allocation is returned to the system.

It is often useful to look at the "Resident Set Size" vs the raw size of the memory allocation. The RSS is the ammount of pages/bytes that is kept in real memory and does not go out to paging/swapping. Over long periods of time, this indicator tells you how much of your allocated memory is really being used (referenced).

However, a recursive call is not necesarilly a strain in the memory subsystem, unless you have a huge number of calls. If this is the case, you should try to reduce the memory footprint of the subroutine by using as little variables local to the subroutine as possible and passing the least arguments possible to save on stack space.

Hope this helps...


In reply to Re: Re: Recursion Problem by fokat
in thread Recursion Problem by sparky8342

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.