Nope, I'm sure that all the requests are served by the same thread.

Anyway, just to make you sure, I'm adding a directive to my httpd.conf file: ThreadsPerChild 1
This way, only one thread is started and can be serving requests.

Actually, making several tests brought interesting results:

Test 1:
#******************************************
use strict;
package mypack;
my $tmp;
$tmp .= 'a';
print '$tmp value: ' . $tmp;
print ' - address: ' . \$tmp . "\n";
#******************************************

It brings:
$tmp value: a - address: SCALAR(0xd7059c)
$tmp value: a - address: SCALAR(0xcf4178)
$tmp value: a - address: SCALAR(0xcf42a4)
$tmp value: a - address: SCALAR(0xcf42bc)

So, different memory blocks used for the same lexical variable. (not what we could expect)

Test 2:
#******************************************
use strict;
package mypack;
our $global;
my $tmp;
$tmp .= 'a';
print '$tmp value: ' . $tmp;
print ' - address: ' . \$tmp;
print ' - global address: ' . \$global . "\n";
#******************************************

Here, I'm testing the memory block of a global variable as well.

This brings:

$tmp value: a - address: SCALAR(0xcf4634) - global address: SCALAR(0xcf464c)
$tmp value: a - address: SCALAR(0xcf4634) - global address: SCALAR(0xcf464c)
$tmp value: a - address: SCALAR(0xcf4634) - global address: SCALAR(0xcf464c)
$tmp value: a - address: SCALAR(0xcf4634) - global address: SCALAR(0xcf464c)

As you can see, now, both the lexical and global variables are keeping their memory block (but the lexical is reset after each call, because going out of scope) So, when any global suymbol comes into play, it seems that lexicals are keeping their memory location.

And to prove that, let's try:
Test 3:
#******************************************
use strict;
package mypack;
my $tmp;
$tmp .= 'a';
print '$tmp value: ' . $tmp;
print ' - address: ' . \$tmp . "\n";
$mypack::dummy;
#******************************************

Here, this is the same as test 1, except that I'm referring to a global variable at the end of the script.

Here, and contrary to test 1, the lexical is keeping its memory block:

$tmp value: a - address: SCALAR(0xa39f3c)
$tmp value: a - address: SCALAR(0xa39f3c)
$tmp value: a - address: SCALAR(0xa39f3c)
$tmp value: a - address: SCALAR(0xa39f3c)

(=> consistant with Test2: referring to a global variable seems to force lexicals to keep their memory block)

But surprisingly enough, if I run another test, similar to test3, but this time, my reference to the global variable is the last but one statement, instead of being the last one:

Test 4:
#******************************************
use strict;
package mypack;
my $tmp;
$tmp .= 'a';
print '$tmp value: ' . $tmp;
$mypack::dummy;
print ' - address: ' . \$tmp . "\n";
#******************************************

This time, this brings:

$tmp value: a - address: SCALAR(0xaf73c4)
$tmp value: a - address: SCALAR(0xcf48d4)
$tmp value: a - address: SCALAR(0xcf45c8)
$tmp value: a - address: SCALAR(0xcf4598)

So, just moving the global symbol statement one statement up messes up the results...

All that is surprising, isn't it?

Does anyone has any explanation?

Anyway, if noone can explain that, I think I'll stop trying to understand everything and just assume that lexical are keeping their memory block, even if this doesn't seem to always be the case.

Lionel.

----- Original Message ----- From: "Clinton Gormley" <[EMAIL PROTECTED] >
To: "Lionel MARTIN" <[EMAIL PROTECTED]>
Cc: "Perrin Harkins" <[EMAIL PROTECTED]>; <modperl@perl.apache.org>
Sent: Saturday, May 12, 2007 8:59 AM
Subject: Re: After retrieving data from DB, the memory doesn't seem to befreed up



#******************************************
use strict;
package mypack;

my $tmp;
$tmp .= 'a';
print '$tmp value: ' . $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:

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


Could it be that the request is being answered by different threads,
each one with their own copy of the $tmp variable?

Try restricting apache to using only a single thread, and repeat the
test.

Clint



Reply via email to