in reply to Dumping undef as a constant produces strange REFCNT

It appears that Perl keeps tabs, even on undefs. While the count may be a little off, loading Perl, loading Devel::Peek and compiling your code appears to have created that may undef. :) Surprising isn't it? Try this out:
use Devel::Peek; Devel::Peek::Dump(undef); eval('require File::Find'); Devel::Peek::Dump(undef);
produces on my system:
SV = NULL(0x0) at 0x8ca1b0 REFCNT = 2147483597 FLAGS = (READONLY) SV = NULL(0x0) at 0x8ca1b0 REFCNT = 2147483005 FLAGS = (READONLY)
While
eval('require Devel::Peek'); Devel::Peek::Dump(undef); eval('require File::Find'); Devel::Peek::Dump(undef);
produces:
SV = NULL(0x0) at 0x34a1b0 REFCNT = 2147483602 FLAGS = (READONLY) SV = NULL(0x0) at 0x34a1b0 REFCNT = 2147483010 FLAGS = (READONLY)
On each run, the difference between the two REFCNTs is 592. Although it seems strange that I end up with fewer REFCNTs.

Replies are listed 'Best First'.
Re^2: Dumping undef as a constant produces strange REFCNT
by Kc12349 (Monk) on Aug 24, 2011 at 22:38 UTC

    It does indeed seem to be counting down as more use/require etc statements are added or eval'd. In fact, any successful eval will also lower the count. Something as simple as eval('#') lowers the count by one.

    The below gives me the highest output count I can get of 2147483604. My guess would be that 2147483647, max val for signed long, is the starting point.

    I'm also curious whether this is some real count value or some artifact of Devel::Peek

    require Devel::Peek; Devel::Peek::Dump(undef); # SV = NULL(0x0) at 0x993788 # REFCNT = 2147483604 # FLAGS = (READONLY)

      I'm also curious whether this is some real count value or some artifact of Devel::Peek

      It's the real value of the REFCNT field, but it does not indicate the number of references to that scalar.

      My guess would be that 2147483647, max val for signed long, is the starting point.

      Yes, or more precisely, the midpoint of 32-bit unsigned ints (even on a 64-bit build).

      The max value wouldn't be good because it's possible to increase it.

      $ perl -E' sub show { say &Internals::SvREFCNT( \undef ); } show(); push @a, \undef for 1..5; show(); ' 2147483623 2147483628

      Of course, it's also possible to reduce it.

      $ perl -E' sub show { say &Internals::SvREFCNT( \undef ); } show(); { my @a; $#a = 5; } show(); ' 2147483623 2147483617