develooper Front page | perl.perl5.porters | Postings from January 2002

Re: [BUG?] Bare block lexical memory leak?

Thread Previous | Thread Next
From:
Jarkko Hietaniemi
Date:
January 21, 2002 12:44
Subject:
Re: [BUG?] Bare block lexical memory leak?
Message ID:
20020121224355.F21767@alpha.hut.fi
On Mon, Jan 21, 2002 at 03:28:47PM -0500, Michael G Schwern wrote:
> This came up earlier.  Why shouldn't the following two programs use
> the same amount of memory:
> 
>     { my $x = 1 x 100_000 }
> 
> and
> 
>     { my $x = 1 x 100_000 }
>     { my $y = 1 x 100_000 }
> 
> the latter uses up more memory than the former, as if the memory
> allocated for $x is never released back into perl's free memory pool.
> 
> What I'd expect is that N bytes be allocated for $x and then released
> back to perl at the end of the block.  When $y is allocated, perl uses
> that old memory rather than requesting more from the system.

There are leaks and then there are leaks.  A serious leak means that
if run in a loop, the memory use keeps growing.  Try the above inside
while(1).

In this particular case I would be surprised if that is a real leak.
More likely Perl just likes to keep around the memory for the
lexicals, to avoid the time-consuming work of creating them anew at
each block enter.

(Virtual) memory size alone is not indicative of much anything, except
the maximum virtual memory footprint ever.  More interesting are the
resident set size, and the trends over time.

> -- 
> 
> Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
> Perl Quality Assurance	    <perl-qa@perl.org>	       Kwalitee Is Job One
> Manipulation is its own reward
> 	http://www.goats.com/archive/010430.html

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About