I'm not exactly sure that the "correctness" of a refcount can be determined, as one would have to scan all memory available to Perl for references to the SV in question, and even then the memory pointing to it might not be in use anymore.

What I think should be feasible would be a (tree-structured?) dump of all memory references/SVs, together with their reference count. Then you can liberally sprinkle those calls to the dumper around and see where there is change in the tree when there should be none. On the other hand, the signal to noise ratio here is pretty bad I guess, as pretty much every op allocates or deallocates memory...

I guess that the only other recourse would be valgrind or another memory bounds checker, but I'm not sure if they (can) catch and diagnose double frees via refcount mess-ups. Maybe you can trick Perl into not reusing existing SVs, so you then get a real leak or a real access violation?

I have never done any of this, and the only thing possible without any too deep XS magic seems to me the tree dump, courtesy of Scalar::Util and PadWalker, and the output of that won't necessarily be helpfull...


In reply to Re: Mark-and-sweep-like mechanism to verify refcount integrity by Corion
in thread 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.