in reply to Re: Improving memory performance
in thread Improving memory performance

Good points but one question. I was under the impression that Perl normally hangs onto the last pad values as an optimization. Is this only in subs or does this happen with all scopes? I think it does hang on to them or I don't think the my $x if 0 behaviour would occur. If this is the case and you have very large lexical data structures I would think you would want to explicitly undef them at the end of the scope.

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Re: Improving memory performance
by Elian (Parson) on Oct 04, 2002 at 14:26 UTC
    There's only one pad per subroutine, so it's per-sub.
      Excuse my ignorance, I maybe just reading your answer the wrong way but from perlguts
      So each subroutine is born with an array of scratchpads (of length 1). On each entry to the subroutine it is checked that the current depth of the recursion is not more than the length of this array, and if it is, new scratchpad is created and pushed into the array.


      -Lee

      "To be civilized is to deny one's nature."
        Right, perl keeps a stack of pads per sub, but each sub only has a single pad in play at once. What I was talking about is something like:
        sub foo { my $bar; { my $bar; { my $bar; } } }
        While there are three blocks, and three $bars in there, there's still only one pad. Leaving the inner blocks doesn't exit any pads, nor does it clean any pads up. (The compiler plays some magic games to determine which $bar in the sub pad is in effect at any particular line of the sub)