OK, The bigger picture. Here goes ...

It basically has to do with circular references.
To deal with them we could use Scalar::Util::weaken or just cleanup the objects manually.
Scalar::Util::weaken won't work for me because the code often refers to a "parent" object via a "child" and vice-versa. I'll illustrate:

sub circ_ref { my $dad = {}; my $son = {}; $dad->{son} = $son; $son->{dad} = $dad; Scalar::Util::weaken $son->{dad}; return $dad; } my $dad = circ_ref(); # All is well my $son = circ_ref()->{son}; # Doh! Who's your daddy? print Data::Dumper::Dumper $dad, $son;

So instead I have to cleanup the objects manually, but at what point? The references to either "parent" or "child" may hang around for while. Only when they have both gone can I cleanup the circ-ref. To do this I need to know when the REFCNTs have dropped to 1.

So I was trying to find a way to "hook" SvREFCNT_dec for these objects, but I guess this is just not possible.
Is there another way to do the cleanup?


In reply to Re: Intercept any changes to the sv_refcnt/SvREFCNT of an object by vernonlyon
in thread Intercept any changes to the sv_refcnt/SvREFCNT of an object by vernonlyon

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.