Check out this code. It looks like in a subroutine the clean up of lexical variables in a "if" statement is not done until after the sub exits:
use strict;
package foo;
our $counter = 0;
sub new {
my $class = shift;
bless {id=>$counter++},$class;
}
sub DESTROY{
my $self = shift;
print "DESTROYING $self->{id}\n";
}
package main;
test();
print "Back in main\n";
sub test{
print "Entering test\n";
if (1) {
my $foo = foo->new();
}
if (1) {
my $foo = foo->new();
}
if (1) {
my $foo = foo->new();
}
print "Leaving test\n";
}
__OUTPUT__
Entering test
Leaving test
DESTROYING 0
DESTROYING 1
DESTROYING 2
Back in Main
UPDATE The point of showing this code, is that maybe it is not a memory leak, but merely a delay in clean up