I'm working on a module that creates a HASH that won't increment the reference count of references that are stored inside it. This can be used to store objects, but without interfere in the DESTROY mechanism, since the references in this HASH won't count.

But now I have a problem, how to know if a reference was cleaned/destroied? I need to know that to automatically remove references/objects from the HASH and free 100% of the memory that should be free after clean that variable.

Note that the behavior of a SCALAR that holds a reference after have it cleaned is strange:

$hash_nor_ref->{ref} = {} ; #will have REFCNT = 0 on clean $hash_nor_ref->{ref} = [] ; #will have REFCNT = 0 on clean $hash_nor_ref->{ref} = \'' ; #will have REFCNT = 1 on clean $hash_nor_ref->{ref} = bless({}) ; #before destroy have a reference to + a blessed HASH, after destroy it will have a reference to a SCALAR, +with REFCNT = 1.
So, there is a better way to know if the reference is dead, some flag, internal command different than SvREFCNT()?

If is not possible to have a better way to know that I will need to map the behaviors of dead references and work over that, but I don't think that this will work very well.

By the way, you can take a look in what was already done: Hash-NoRef-0.01. (Use it as a beta version)

Graciliano M. P.
"Creativity is the expression of the liberty".


In reply to Playing with the Reference Count of variables (to create a POOL of objects wihtout mess with DESTROY). by gmpassos

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.