[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: After retrieving data from DB, the memory doesn't seem to be freed up


(sorry, I posted the message below from another email address hours ago, and it didn't get publish - see below if anyone could reply)


On May 10, 2007, at 6:52 PM, Andy Armstrong wrote:

On 10 May 2007, at 23:48, Jonathan Vanasco wrote:
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

No you don't:

  sub frog {
      my $x;
      $x .= 'x';
      return $x;
  }


sorry, i should have clarified, I meant that to be:

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

package frog;
my $x;

sub leap {
$x .= 'x';
return $x;
}

Yes, here, that's consistant with what we were saying yesterday:
$x is a lexical variable, so the memory allocated to it remains allocated
across requests.
But here, as $x is referenced by your leap sub, which is a global symbol, $x
content is never erased.

Actually, I tried something else that surprised me a bit:

use strict;
package mypack;

my $tmp;
$tmp .= 'a';
print 'main $tmp: ' . $tmp . ' - address: ' . \$tmp . "\n";


I am running this script in a ModPerl::Registry environment.

In this situation, the first time I'm running the script, I can see this:

main $tmp: a - address: SCALAR(0xd725e0)

And then, in subsequent calls:

main $tmp: a - address: SCALAR(0xd77bf4)
main $tmp: a - address: SCALAR(0xd77d20)
main $tmp: a - address: SCALAR(0xd77d38)

Of course, I understand why $tmp value is reset during each call (the
lexical variable goes out of scope) but, as we can see, the address used by
the variable is changing as well during each request, and this fact doesn't
seem consistent with what has been said before (i.e. that memory stayed
allocated to lexical variables across requests)...

I suppose I am still missing something, but what?

Lionel.


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.