I was reading How can I access the ref count of a Perl hash?, and there both Devel::Refcount::refcount and Devel::Peek::SvREFCNT are suggested.
But they don’t return the same reference counts. Why is that?
Here a modified example from perldoc Devel::Refcount:
use Devel::Peek;
use Devel::Refcount;
my $anon = [];
printf "Anon ARRAY $anon has %d/%d reference\n",
Devel::Refcount::refcount($anon),
Devel::Peek::SvREFCNT($anon);
my $otherref = $anon;
printf "Anon ARRAY $anon now has %d/%d references\n",
Devel::Refcount::refcount($anon),
Devel::Peek::SvREFCNT($anon);
which prints out:
Anon ARRAY ARRAY(0x8b10818) has 1/1 reference
Anon ARRAY ARRAY(0x8b10818) now has 2/1 references
Notice the last 2/1 discrepancy…
(If it turns out I’m not doing something stupid, I’ll add a link from How can I access the ref count of a Perl hash? to here)
I can’t say that I grok all of it yet, but your question is answered prominently in the
Devel::Refcountperldoc