|P is for Practical|
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