I wonder what would happen if the reference count were incremented before returning:my $dsgn = create_new(); $dsgn->(method); sub create_new { my $ret = new (c++_object); return $ret; }
I don't think there exists a perl function/module that implements a reference count increment - in which case you'd need to do it with Inline::C/XS/SWIG. (I guess SWIG can help out there ... I know nothing about it.) Even if incrementing the reference count does work, that doesn't guarantee that it's the most appropriate thing to do.my $dsgn = create_new(); $dsgn->(method); sub create_new { my $ret = new (c++_object); refcnt_inc($ret); return $ret; }
use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void refcnt_inc(SV * sv) { SvREFCNT_inc(sv); } SV * get_refcnt(SV * sv) { return newSVuv(SvREFCNT(sv)); } EOC $x = 1; print get_refcnt($x), "\n"; refcnt_inc($x); print get_refcnt($x), "\n";
In reply to Re^3: C++ object & PERL garbage collection
by syphilis
in thread C++ object & PERL garbage collection
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |