xslate / p5-Mouse

Lightweight class builder for Perl, as a subset of Moose
https://metacpan.org/release/Mouse
Other
46 stars 32 forks source link

Memory leak on attribute triggers #7

Closed agjohnson closed 10 years ago

agjohnson commented 10 years ago

Defining a trigger on an attribute seems to cause a memory leak when redefining the attribute. It seemed as long as there was a coderef, even an empty coderef, the leak would be produced.

Example that will show the actual leak

package Foo;

use Mouse;

has 'bar' => (
    is => 'rw',
    trigger => sub { }
);

1;
package main;

my $foo = Foo->new(bar => 'TEST');

while (1) {
    $foo->bar('A' x (1000000));
    sleep 1;
}

1;

And the test that shows the leak:

use Test::More;
use Test::LeakTrace;

plan tests => 1;

no_leaks_ok {
    my $foo = Foo->new(bar => 'TEST');
    $foo->bar('bar');
} 'Foobar';

I was able to reproduce on 5.8, 5.14, and 5.18.

gfx commented 10 years ago

Thank you for the report. This issue has been fixed in 1.07 and will be available soon.