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

Re: [perl #109270] leak on accessing anon sub inside another one

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
January 29, 2012 03:40
Subject:
Re: [perl #109270] leak on accessing anon sub inside another one
Message ID:
CAHhgV8gy_FOhqskTEEUXeGrz35omzqZQJtou+QfzQQ6LXY2cbA@mail.gmail.com
On Sat, Jan 28, 2012 at 5:34 PM, Alexandr Gomoliako
<perlbug-followup@perl.org> wrote:
> So, basically using another scalar that holds a sub inside
> another one causes it to leak a lot of memory.
> Tested on 5.8.9, 5.12.4 and 5.14.2:
>
> sub leak {
>    my ($foo, $bar);
>
>    $foo = sub {  &$bar   };
>    $bar = sub {  "$foo"  };
>
>    return;
> }
>
>
> # test
>
> sub psprint { print `ps -p$$ -ocommand,vsize` }
> psprint;
> for (1..20000) {
>    leak();
> }
> psprint;

This is called a circular reference, and this kind of leaking is a
well known consequence of reference counting. If you want this not to
happen, try weakening one of the references.

Leon

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