In this node, I ask about a way to catch variables as they go out of scope as to avoid reference caching (update NOT catching) in a Factory-like class. While weak references was suggested as one possible solution, this only works in 5.6, as weak references weren't possible without patching 5.005. I'd like to keep a solution that works in 5.005 as well.

Another suggestion, as given by chip in this node was to use unique IDs that are stored in a package level hash, such that the Factory class stores only these IDs, which does not appear to increase the reference count to the object, such that they can be deleted when they go out of scope. The only problem with this, potentially, is that the counter that acts like a unique ID could roll over, but realistically I would not expect that to happen.

However, thinking about this and any other way to generate a sufficientl unique ID, I though about stringifying the references as a unique ID, that is, instead of this code that chip offered:

$TEMPS{ $self->{ID} = ++$TEMPID } = $self;
I would use:
$TEMPS{ $self->{ID} = "$self" } = $self;
Is there any serious problems with this? As opposed to the int case, these will stop to resolve right once your memory is full, which problems would be expected to happen anyway. I'm pretty sure that references would remain fixed in memory once created, but I can't see any other caveats. Any concerns about this?

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important


In reply to Using stringified refs for unique IDs? by Masem

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.