Maybe the following will help (and yes im pretty sure this is at least part of the reason for his leak):
#!perl -l sub F { my $foo=bless[]; print "create:$foo"; sub T { print "T"; push @$foo,"test"; } print "F"; push @$foo,"bar"; } sub DESTROY { print "destroy: @_:@{$_[0]}" } F; T; T; T; F; __END__ create:main=ARRAY(0x15d53d8) F T T T create:main=ARRAY(0x1a4550c) F destroy: main=ARRAY(0x1a4550c):bar destroy: main=ARRAY(0x15d53d8):bar test test test
T only once shares the same $foo with F, right at the beginning. The first time the sub executes it binds T as a closure to the original $foo and never rebinds it. And since T contains a reference to that $foo, and because T exists in the package table $foo wont be freed until T is destroyed causing $foo's refcount to drop. Thus the OP probably has a number of vars that are filling up without his knowledge behind the scenes. When the inner sub is anonymous, the compiler knows that the closure must be re-resolved each time.
In reply to Re^4: Memory leak
by demerphq
in thread Memory leak
by aplonis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |