So, forgetting all the stuff about faking closures and stuff, your proposing to "just increase the refcount"?

Assuming that you can do that, what happens if the thing you just increased the refcount of, was previously deliberatly weakened by the caller for inclusion into self-referential structure? Or after they've given it to you?

How does it play if your 'array' is initialised by

tie my @a, 'Compact::Array'; @a = ( 'default' ) x 1_000_000;

The refcount on the SV pointing at that constant string 'default' is now 1000000. That's a million chances for it never getting cleaned up properly.

I'm not saying that this isn't possible to do--it is--but these are all things I have had problems with.

It gets even more complicated when you start thinking of the effect of storing references to shared objects and how that plays with threads and threads::shared.

I've spent a fair amount of time looking at the code in threads.xs & shared.xs that has to play similar games with reference counts.

The guys that wrote that code are a darn sight cleverer than I, and still those modules have probably been the source of more leakage than amost any other. That tells me that it's not trivial, even if my failure to make it work properly is down to my stupidity.

In each case, there are a subset of situations in which any given solution will work fine, and for a given specific task, they work okay, but for a general purpose solution, you need to consider all these possibilities and more.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re^7: Techniques On Saving Memory by BrowserUk
in thread Techniques On Saving Memory by Limbic~Region

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.