When calling a C function from Perl, for example using Inline::C
:
use feature qw(say);
use strict;
use warnings;
use Inline C => './test.c';
say "Calling test()..";
test();
say "Finished.";
where test.c
is:
void test()
{
SV *sv_variable = newSVpv("test", 0);
// do something..
//SvREFCNT_dec(sv_variable); // free variable
printf( "Returning from test()..\n");
return;
}
The script seems to work fine whether I call SvREFCNT_dec(sv_variable)
or not. According to perlguts
:
To free an SV that you've created, call SvREFCNT_dec(SV*). Normally this call is not necessary