Subject: | Memory leak (cycle) with meta method getting $meta from closure. |
In MooseX::Traits::Util::new_class_with_traits() an anonymous class,
$meta, is created. A meta method is added, which returns $meta from
closure, resulting in a cycle.
Making $meta a weak ref with Scalar::Util::weaken() seems to fix it.
Cycle (1):
$Class::MOP::Class::Immutable::Moose::Meta::Class::A->
{'methods'} => \%B
$B->{'execute'} => \
%MooseX::Method::Signatures::Meta::Method::C
$MooseX::Method::Signatures::Meta::Method::C->
{'parsed_signature'} => \%Parse::Method::Signatures::Sig::D
$Parse::Method::Signatures::Sig::D->{'_positional_params'} => \
%Parse::Method::Signatures::ParamCollection::E
$Parse::Method::Signatures::ParamCollection::E->{'params'} =>
\@F
$F->[0] => \
%Class::MOP::Class::__ANON__::SERIAL::5::G
$Class::MOP::Class::__ANON__::SERIAL::5::G->{'__MOP__'} => \
%Moose::Meta::Class::H
$Moose::Meta::Class::H->{'methods'} => \
%I
$I->{'meta'} => \&J
$J variable $meta => \$K
$$K => \%Moose::Meta::Class::H