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

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

Thread Previous | Thread Next
Jarkko Hietaniemi
January 21, 2002 12:44
Re: [BUG?] Bare block lexical memory leak?
Message ID:
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

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   <>
> Perl Quality Assurance	    <>	       Kwalitee Is Job One
> Manipulation is its own reward

$jhi++; #
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About