in reply to Strange memory growth?

And with 5.8.2 on Linux as well.

Oddly enough, this doesn't happen if you do:

foreach 1..6 { my $foo = "perl" x 1000000; sleep 5; }

So, it would seem that Perl doesn't know to reclaim if it is a different scope.

Surprisingly, the following also "loses" memory:

my $foo; if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; }
Uses about 28 Mb at the end (the original uses 48 Mb).

Maybe something for 5.8.3 to look at ;-)

Liz

Replies are listed 'Best First'.
Re: Re: Strange memory growth?
by meetraz (Hermit) on Nov 07, 2003 at 20:52 UTC
    I wonder why having the my inside the block would cause it to use more memory than having it outside?

    And even without the my, it still uses 28M:

    sleep 5; if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; } if (1) { $foo = "perl" x 1000000; sleep 5; }
Re: Re: Strange memory growth?
by Anonymous Monk on Nov 07, 2003 at 23:31 UTC
    I can't be sure, but it may have something to do with those if (1) {} blocks getting optimized away.

      It still get's put inside a block:

      $ perl -MO=Deparse -e 'if(1) { $foo = "perl" x 1000000; sleep 5; }' do { $foo = 'perl' x 1000000; sleep 5 };

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

        You're right, that was silly of me. Also, you would not get a memory growth evry 5 seconds in that case, that would just affect compile time.