Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Thank you MarkM, for your insights into the memory management of Perl. Very very very helpful.

So to recap what i have discovered..

*) Perl DOES do something different when a function calls itself, vs calling another function. If a function which is currently invoked, gets invoked by another or itself, it will allocate more memory, due to the fact that the current variables are already in use.
I didnt exhibit the extra memory allocations in my Non recursive nested calls, because no functions were ever invoked on themselves. Thus no need to allocate more memory.
It is not like C, where the functions local variables are pushed onto a stack, and it doest matter if it calls itself or another function. It would all be pushed and popped off correctly.

As my test code above demonstrated, running the "leaky" recurse function in a loop, does not accumulate more memory. It is reused. So , technically, its not a memory leak.

In my certain situation, where at the START of my program i do a deeply nested file glob, storing all filenames, then NEVER CALLING that function again, i end up with a program which runs on less memory, and the possibility of virtual memory disk swaps is great.

To get around this, i will create a seperate perl script which file globs to a text file. I will call this script via a system command, and load the text file it created. That way i have no recursion at the start of my main program, more memory and less disk swaps because of virtual memory.

So to continue my education, does anyone know or can point me to the sourcefile or document which technically explains how PERL deals with memory, global vars, local vars, etc? What technically happens when you do a local() or a my? I know C, C++/, many flavors of asm, so the more low level the better.

thank you again
rob

In reply to Re: Re: Nested Calls, Recursion and MEMORY by Anonymous Monk
in thread Nested Calls, Recursion and MEMORY by robdog

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (10)
    As of 2014-04-18 08:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (464 votes), past polls