While writing some code to track down a memory leak, I came up with the fol=
lowing program using Moose 0.93. It appears to show a few leaks:=0A=0A #=
!/usr/bin/env perl=0A=0A use Modern::Perl;=0A use Devel::LeakGuard::O=
bject qw( GLOBAL_bless );=0A use Devel::LeakGuard::Object::State;=0A=0A =
my $leakstate;=0A=0A BEGIN {=0A $leakstate =3D Devel::LeakGuard:=
:Object::State->new(=0A on_leak =3D> sub {=0A my $report =
=3D shift;=0A my @leaks =3D sort { $b->[1] <=3D> $a->[1] } # hi=
gh refcount first=0A map { [ $_ =3D> $report->{$_}[1] ] } # c=
lass, refcount=0A keys %$report;=0A printf "%-45s %s\n=
" =3D> qw/Class Refcount/;=0A say "-" x 54;=0A=0A foreach=
my $leak (@leaks) {=0A printf "%-50s %d\n" =3D> @$leak;=0A =
}=0A }=0A );=0A }=0A {=0A package Foo;=0A =
use Moose;=0A has me =3D> ( is =3D> 'rw' );=0A }=0A {=0A pa=
ckage Bar;=0A use Moose;=0A has me =3D> ( is =3D> 'rw' );=0A }=
=0A {=0A=0A package Baz;=0A sub new { bless {} =3D> shift }=0A=
}=0A my $foo =3D Foo->new;=0A $foo->me($foo);=0A my $bar =3D B=
ar->new;=0A $bar->me($bar);=0A my $baz =3D Baz->new;=0A=0AAnd the out=
put:=0A=0A Class Refcount=0A =
------------------------------------------------------=0A Class::MOP::Me=
thod::Accessor 221=0A Class::MOP::Attribute =
112=0A Class::MOP::Method =
48=0A Class::MOP::Class::Immutable::Class::MOP::Class 43=0A =
Class::MOP::Instance 32=0A Class::MOP::=
Method::Constructor 30=0A Moose::Meta::TypeConstraint=
19=0A Class::MOP::Method::Wrapped =
17=0A Class::MOP::Class 8=0A =
Moose::Meta::Method::Accessor 4=0A Moose::Meta::T=
ypeConstraint::Parameterizable 3=0A Moose::Meta::Class =
3=0A Moose::Meta::Attribute =
3=0A Class::MOP::Package 2=0A Moo=
se::Meta::TypeConstraint::Class 2=0A Moose::Meta::Instan=
ce 2=0A Bar =
1=0A Config =
1=0A Baz 1=0A Moose::M=
eta::TypeConstraint::Registry 1=0A Foo =
1=0A=0AOur actual application has some of those =
refcounts in the thousands (it gets fun when I throw Catalyst and DBIx::Cla=
ss into the mix). Am I just misunderstanding this output or does Moose lea=
k and Class::MOP leak? (I'm suspicious because it shows that Baz still has=
a refcount of one).=0A=0ACheers,=0AOvid=0A--=0ABuy the book - http=
://www.oreilly.com/catalog/perlhks/=0ATech blog -
http://use.per=l.org/~Ovid/journal/=0ATwitter -
http://twitter.com/OvidPerl==0AOfficial Perl 6 Wiki -
http://www.perlfoundation.org/perl6