Subject: | possible memory leaks |
Date: | Thu, 11 Sep 2014 11:37:37 -0700 |
To: | bug-moose [...] rt.cpan.org |
From: | Robert Messer <rmesser [...] intellisurvey.com> |
I am trying to track down some fairly severe memory leaks our software, and some have been experimenting with various CPAN modules that help locate leaks. As part of that, I tried adding a UNIVERSAL::DESTROY method that checks for cycles in the global destruction phase, under the theory that object that survive to that point are likely leakers. Here is the test script:
use strict;
use Devel::Cycle;
package Foo {
use Moose;
sub BUILD {
my $self = shift;
$self->{circle} = $self;
}
}
# Install a universal DESTROY method to check for leaks during the global destruction phase, under
# the theory that objects that survive until global destruction are likely candidates for leaking.
# NB: this doesn't catch all leaks, apparently because some cycles are broken by perl before we
# get here. Maybe?
sub UNIVERSAL::DESTROY {
my $self = shift;
if (${^GLOBAL_PHASE} eq 'DESTRUCT') {
find_cycle($self);
}
}
my $f = Foo->new();
This unfortunately didn't report the leak in my own example Foo object, but it does report tons of cycles within Moose code. For example, there are a lot of this form:
Cycle (1):
$Class::MOP::Instance::A->{'attributes'} => \@B
$B->[0] => \%Class::MOP::Attribute::C
$Class::MOP::Attribute::C->{'associated_methods'} => \@D
$D->[0] => \%Class::MOP::Method::Accessor::E
$Class::MOP::Method::Accessor::E->{'attribute'} => \%Class::MOP::Attribute::C
and some like this, possibly related to the one above, since both reference attribute and associated_methods:
Cycle (1):
$Class::MOP::Method::Accessor::BT->{'body'} => \&BU
$BU variable $attr => \$BV
$$BV => \%Class::MOP::Attribute::BW
$Class::MOP::Attribute::BW->{'associated_methods'} => \@BX
$BX->[0] => \%Class::MOP::Method::Accessor::BY
$Class::MOP::Method::Accessor::BY->{'body'} => \&BZ
$BZ variable $class => \$CA
$$CA => \%Class::MOP::Class::Immutable::Class::MOP::Class::CB
$Class::MOP::Class::Immutable::Class::MOP::Class::CB->{'attributes'} => \%CC
$CC->{'auto_deref'} => \%Class::MOP::Attribute::CD
$Class::MOP::Attribute::CD->{'associated_methods'} => \@CE
$CE->[0] => \%Class::MOP::Method::Accessor::CF
$Class::MOP::Method::Accessor::CF->{'body'} => \&CG
$CG variable $attr => \$CH
$$CH => \%Class::MOP::Attribute::CD
If you run the script above you should be able to see the same spew of output (1900+ lines) I'm getting. I'm using Moose 2.1211, Perl 5.20.0. Are these valid leaks? Perhaps the 'attribute' in Class::MOP::Method::Accessor needs to be weakened?
Rob