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)


In reply to Re: Tracing zombie variables. by demerphq
in thread Tracing zombie variables. by ash

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.