I'm suffering from the dreaded attempts to free unreferenced scalars.

My understanding is that the cause of the problem is not local to the manifestation. Something somewhere (usually an XS module) has erroneously allowed an SV's refcount to drop to zero even though it still has a pointer to it. Something else then re-allocates that SV.

Now we have two unrelated scalars sharing an SV an totoally random things could happen.

The first thing then drops the refcount again. When the second thing tries to drop the refcount we get the warning.

What I need is something like a mark-and-sweep GC which doesn't actually GC but just checks that all the refcounts are right. By calling this at suitable points in the code I could perhaps narrow down the culpit.

I've had a look and Devel::Leak and various other Devel::* modules on CPAN but I've failed to find anything that attempts to walk the entire perl symbol table / stack / pads. Has anything like this ever been attempted?

UPDATE 2004-10-06: Although I still think there can be a problem with bad refcounts and action-at-a-distance I'm beginnning to suspect what's actually happening in my application is rather more straight forward. I now suspect that it has to do with aliases to elements of transitory tied hashes created in an object's '%{}' overload method.


In reply to Mark-and-sweep-like mechanism to verify refcount integrity by nobull

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.