The "weak" references from Scalar::Util are a great thing to know about. I was trying to create a reference that wasn't counted, and that's exactly what the weaken() function does.

The only problem is that during processing, variables may fall out of scope and get undefined before their time is up. That's the reason I was trying to construct a cache. The cost of constructing an object is expensive enough (RDBMS) that keeping it around for a while is a good idea, even if it has temporarily fallen out of use.

mojotoad does have a point. This is precisely what Perl does with its own garbage collection routines. I don't intend to replace this for everything, just delay it for those objects which need to be preserved.

It isn't always practical to pass around all the data you need from function to function, especially if they are unrelated. The cache will serve to link together records that are not explicitly linked, but implicitly, something that isn't always clear in advance.

What I'm really trying to do is load any given DB row once, and work with it until it "expires", which is usually at the end of the transaction, though for some pseudo-static data, this could be considerably longer. Perl treats all objects as being equal, and discards them when it gets around to it. I'm looking for some degree of control over the process.

Having a refrerence count isn't vital, but sure would come in handy when trying to prune the cache.

In reply to Re^2: Reference Count by tadman
in thread Reference Count by tadman

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.