UPDATE:
I didnt notice your comment about OO when i first wrote this, so im comenting now. Your concern about OO is unfounded. The overhead to which you refer is a consequence of method call look up. In the case I proposed this is not really a factor as the only method calls that I suggest you support is new() and DESTROY() and they only get called once per object and thus the overhead is negligable.
END UPDATE
Well, there arent really any good ways to do this. However one trick that you may find useful (assuming you are doing OO and that your nodes are discrete objects) is to keep track of the number of created nodes and the number of destroyed nodes, like so
package LL::Node;
{
my $allocated=0
sub new {
$allocated++;
bless {},$_[0];
}
sub DESTROY {
$allocated--;
}
sub END {
warn "There were $allocated nodes that have not been properly free
+d dusing destruction.\n"
if $allocated;
}
}
# other stuff
This way you will at least know how many objects with cyclic references that havent been freed. Of course you could just use the DESTROY sub to ensure that any links are broken
sub DESTROY {
$allocated--;
$_[0]->{next}=undef;
$_[0]->{prev}=undef;
}
Assuming of course that you are using hash based nodes...
Also if you wanted to get into really deep mojo you could use Scalar::Util which provides a way to make a "weak" reference, but personally i wouldnt do that...
HTH
Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)
|