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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |