perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Schindl <>
Subject Re: No image creation in mod_perl (Or Perl Memory Management is a beast)
Date Wed, 29 Mar 2006 07:23:01 GMT
And even "worse":


use Benchmark;

$t0 = new Benchmark;
$t1 = new Benchmark;
# Memory has grown on my machine to 110 MB
#sleep 20;
$t2 = new Benchmark;
$t3 = new Benchmark;
# Memory has resides on my machine on 110 MB

print "First run took: " . timestr(timediff($t1, $t0)) . "\n";
print "Second run took: " . timestr(timediff($t3, $t2)) . "\n";


sub bla {
   my $var = &blo($ARGV[0]);
#   undef $var;

sub blo {
   my $var = "";
      for( 1 .. 20_000_000  ) {
            $var .= "xxx";

      #   undef $var;
      if( ! defined $_[0] ) {
         return $var;
      } else {
         return \$var; ## This will also result in the fact that perl
                       ## releases the memory after the sub has been
                       ## ended

Just to quote perl gurus from the p5p you'll get to here something like

Yitzchak Scott-Thoennes:
Memory is *not* released back to perl.  Lexicals(*) hold on to their
storage space, including the string buffer, under the presumption that
they will be reused.  Perl's memory management strategy can be
described as allocate as early as possible and for as long as

Please note the fact that Lexicals!!! hold their values until they are
undef-ed or they are also GCed when returned as references. You should
also note the time used in the second run (especially sys-time) which is
much lower because memory allocation has not to be done.

>>>Can I confirm that in the Windows implementation, if a thread allocates
>>>requires 100MB of memory and then releases it, the next thread can reuse
>>>that memory?

Because the above said applies to any perl you won't gain much on win32
because memory allocated belongs exactly to the sub it was allocated in ;-)


View raw message