Subject: | memory leak when MooseX::Role::Parameterized is used from inside BUILD |
System:
MooseX::Role::Parameterized-0.23
Perl v8.5.7
SunOS 5.8
Problem:
MooseX::Role::Parameterized has a memory leak, when it is invoked other
than through a direct 'with'.
Example code:
package Test::Role;
use MooseX::Role::Parameterized;
parameter function_name => (
required => 1,
isa => 'Str',
is => 'ro',
);
role {
my $parameter = shift;
my $function_name = $parameter->function_name;
method "$function_name" => sub {
my $self = shift;
return "The stored text for function '$function_name' = 'memory
leak tester'\n";
};
};
package Test::Attribute;
use Moose;
# 1, no leak
#with('Test::Role' => { function_name => 'get_text' });
# 2, leaks
#sub BUILD {with('Test::Role' => {function_name => 'get_text' })};
package main;
for ( my $i = 1; $i <= 1000; $i++ ) {
my $test = Test::Attribute->new( { } );
print $test->get_text;
}
1;
Uncomment '1, no leak' line to run 'test' 1000 times
- memory stays at 10 MB
Uncomment '2, leaks' line to run 'test' 1000 times
- memory slowly increases from 10 MB to 17 MB
- Code is running about a factor 100 slower