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. LeonThread Previous | Thread Next