fng has asked for the wisdom of the Perl Monks concerning the following question:

If i do this
use Scalar::Util qw(weaken); my $count = 3000; do { print "".(`ps -p $$ -o size=`+0)." " if ! ($count % 100); my $x = \("abcdefghijklmnopqrstuvwxyz" x 8000); my $y = $x; weaken $y; } while $count--;
I get

1128 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544

But if I do this
use Scalar::Util qw(weaken); my $count = 3000; do { print "".(`ps -p $$ -o size=`+0)." " if ! ($count % 100); my $x = {x=>"abcdefghijklmnopqrstuvwxyz" x 8000}; my $y = $x; weaken $y; } while $count--;
i get this

1128 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1544 1676 1676 1676 1676 1676 1676 1676 1676 1676 1676 1808 1808 1808 1808 1808 1808

The more iterations, the more it leaks. Why? (perl 5.10.0 here)

Replies are listed 'Best First'.
Re: process size and weaken
by ikegami (Patriarch) on Sep 03, 2009 at 00:25 UTC

    I can reproduce the memory leak with 5.10.0 as well (MSWin32-x86-multi-thread), but not with 5.10.1 (same system).

    Update: Additional info:

    perl5101delta mentions the following fix: "A weak reference to a hash would leak. This was affecting DBI [RT #56908]."

      Hmm... I should upgrade to 5.10.1 as well :)