If you have a complex data structure and iterate over it, I expect refcounting to increase and then decrease the refcount:

C:\>perl -MDevel::Peek -e "$x=[{foo=>1}]; Dump $x; $a=$x->[0]; Dump ($ +a); " SV = RV(0x1aa4ffc) at 0x1a93898 REFCNT = 1 FLAGS = (ROK) RV = 0x1a44bac SV = PVAV(0x1a45f9c) at 0x1a44bac REFCNT = 1 FLAGS = () IV = 0 NV = 0 ARRAY = 0x1a4baac FILL = 0 MAX = 0 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = RV(0x1aa4ff4) at 0x1a44bb8 REFCNT = 1 FLAGS = (ROK) RV = 0x1a44a98 SV = PVHV(0x1a92fec) at 0x1a44a98 REFCNT = 1 # <- only one reference FLAGS = (SHAREKEYS) IV = 1 NV = 0 ARRAY = 0x1a4b9b4 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "foo" HASH = 0x238678dd SV = IV(0x1a989f0) at 0x1a44b88 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = RV(0x1aa4fd4) at 0x1a938e0 REFCNT = 1 FLAGS = (ROK) RV = 0x1a44a98 SV = PVHV(0x1a92fec) at 0x1a44a98 REFCNT = 2 # <- now two references FLAGS = (SHAREKEYS) IV = 1 NV = 0 ARRAY = 0x1a4b9b4 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "foo" HASH = 0x238678dd SV = IV(0x1a989f0) at 0x1a44b88 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1

I guess you can do clever things with aliases to avoid refcounting (as the stack currently is not refcounted), but it's easy to miss just one of these.


In reply to Re^3: WHY copying does happen (fork) by Corion
in thread WHY copying does happen (fork) by Anonymous Monk

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.