I don't know enough about Moose to explain why your attempt using DEMOLISH didn't work. I can suggest an alternative, though.
Another way would be to get a weakened reference to the circular chain.
my $weak_ref; { my $y = Y->new(); weaken( $weak_ref = $y ); $y->{__CIRCULAR__} = $y if $ENV{TEST_THE_TEST}; } ok(!defined($weak_ref), 'circular reference destruction');
I think your method with the following tweak would be more reliable because it allows you to monitor all the objects, not just one. Change
sub { $garbage_collected = 1 }
to
sub { ++$garbage_collected }
Then you can construct a whole bunch of objects and make sure they all got destroyed.
In reply to Re: unit-testing garbage collection with Moose
by ikegami
in thread unit-testing garbage collection with Moose
by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |