Skip to content

Instantly share code, notes, and snippets.

@oylenshpeegul
Created June 3, 2015 01:56
Show Gist options
  • Save oylenshpeegul/4165e7cbff9e546ad26e to your computer and use it in GitHub Desktop.
Save oylenshpeegul/4165e7cbff9e546ad26e to your computer and use it in GitHub Desktop.
Compare Devel::Refcount::refcount with Internals::SvREFCNT
#!/usr/bin/env perl
use v5.16;
use warnings;
use Devel::Refcount qw(refcount);
my $href = {};
say "BEGIN:" . refcount($href);
say "SvREFCNT: ", Internals::SvREFCNT($href);
my $href2 = $href;
say "VAR:" . refcount($href);
say "SvREFCNT: ", Internals::SvREFCNT($href);
f1($href);
f2($href);
my $n1 = f3($href);
say "AFTER f3:" . refcount($href);
say "SvREFCNT: ", Internals::SvREFCNT($href);
my $n2 = f4($href);
say "AFTER f4:" . refcount($href);
say "SvREFCNT: ", Internals::SvREFCNT($href);
sub f1 {
say "f1:" . refcount($_[0]);
}
sub f2 {
my $v = shift;
say "f2:" . refcount($v);
}
sub f3 {
return { args => \@_ };
}
sub f4 {
return { args => [@_]};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment