Skip Menu |

This queue is for tickets about the Tree-Simple CPAN distribution.

Report information
The Basics
Id: 7512
Status: resolved
Priority: 0/
Queue: Tree-Simple

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.08
Fixed in: (no value)



Subject: memory leak (DESTROY is useless as you have it)
Heres one which won't leak memory, of course you still have to actually invoke ->DESTROY because of the circular refs, undef $tree won't work (you can remedy that with Scalar::Util's weaken). sub DESTROY { my ($self) = @_; local $_; # sub isLeaf should probably make sure _children is not undef unless( $self->{_children} and $self->isLeaf()){ defined $_ and $_->DESTROY() for @{$self->{_children}}; } delete $self->{$_} for keys %$self; return; }
It might also be a good idea to add undef $_[0]; # magic at the end of DESTROY. Example how it works sub f { undef $_[0] } $_=\1; print 1, $_,$/; print 1, f($_),$/; print 1, $_,$/; __END__ 1SCALAR(0x1824610) 1 1
Actually, make that eval { undef $_[0]}; # magic
DESTROY method has been fixed, and properly removes references. Also added a test to check this (it only runs of the user has Test::Memory::Cycle installed), and added documentation to encourage the user to call DESTROY method to clean up circular references.