Skip Menu |
 

This queue is for tickets about the MooseX-Declare CPAN distribution.

Report information
The Basics
Id: 52295
Status: new
Priority: 0/
Queue: MooseX-Declare

People
Owner: Nobody in particular
Requestors: harv [...] ruin.nu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.32
Fixed in: (no value)



Subject: Memory leak with anonymous classes, attributes and method signatures.
Download (untitled) / with headers
text/plain 1.2k
Not sure if this is considered abuse of this module, if it is I wouldn't mind being pointed in the right direction, but I'm trying to write a plugin system where I can load and unload dynamically, so new code can be loaded without restarting the whole system. Each plugin being defined by an anonymous class. However, when I use MooseX::Declare to create these anonymous classes there is a leak of about 40k per instance, and every attribute, method or method modifier adds a bit more to the leak. Declaring methods with a plain sub doesn't seem to contribute anything to the leak, only when using method signatures. Running leaktest.pl, which runs the leak.pl "plugin" 1000 times, the memory usage starts at around 20MB resident and ends somewhere just below 90 MB. Using Devel::Cycle there seems to be a few cycles for each method being added using method signatures. Attributes makes it bail out, so not sure there. When changing it to use noleak, which creates a plain anonymous class using Moose::Meta:Class, the resident memory stays at a stable 6MB. The leak is not massive, but it adds up over time, on my test machine I can live with it, in production there will be fewer code reloads, but it adds up over time.
Subject: leaktest.pl
Download leaktest.pl
text/x-perl 142b
#!/usr/bin/perl use feature ':5.10'; use strict; use warnings; for (1..1000) { my $c = do "leak.pl"; } say "done"; sleep 10; say "bye";
Subject: noleak.pl
Download noleak.pl
text/x-perl 278b
#!/usr/bin/perl use feature ':5.10'; use strict; use warnings; use Moose::Meta::Class; my $class = Moose::Meta::Class->create_anon_class(); my $p = Class::MOP::Package->initialize($class->name); $p->add_method(execute => sub { my ($c,$d) = @_; say "hello"; }); $class;
Subject: leak.pl
Download leak.pl
text/x-perl 150b
#!/usr/bin/perl use feature ':5.10'; use strict; use warnings; use MooseX::Declare; class { method execute ($c,$d) { say "hello $c & $d"; } };


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.