On May 10, 2007, at 6:25 PM, Lionel MARTIN wrote:
So, to sum up, if I have got 10 different scripts in a mod perl environment (let's call them test1.pl....test10.pl), and using lexical variables there. If I first run test1.pl and then, run test2.pl, the only way for test2.p to get access to the memory used by test2.pl is freeing up test1.pl lexical variables, by undefining them?

And what if I run test1.pl twice without undefining its lexical variables? Will the same memory space be used twice, or will each call use different memory space (I'm talking here about situation where the same Perl interpreter is running the script twice in a mod perl environment)?

well, to complicate things, this behavior is PER CHILD...

meaning:

if you run test1.pl 2x and they are both served by the same apache child, then the memory will be reused. if you run test1.pl 2x and they are both served by the different apache children, then the memory will be not be reused.

What you should realize is:
mod_perl behaves like this because it is a persistent process . i believe most other persistent frameworks ( perl or other os) run the same way...
        memory isn't returned because, your scripts effectively never exit.
        in a very bad analogy:
you're really just starting up a big perl program, compiling all the subs , and on every request running a sub or two.
                because the program never ends, the memory is never released
that means the subs stay as-is -- they're in the same state when you enter a block as when you left it on the last request. that also means that variables are sticky -- if you change something from $a= "b" to $a.= "b" , you'll see the var appending b on every iteration
                this isn't a bug or byproduct - its a highly desired feature.
if you write clean perl code, always 'use strict' , and always use the most limiting variable as possible ( package -> sub -> block ) this should rarely be an issue

in essence, mod_perl is used for massive speed optimizations , that means it is at the expense of memory.

Reply via email to