If I write some XS code with a hash that I never expect to return to perl, do I have to free it? If so, how?
The closest I've come up with is hv_undef, but that is only clearing out the contents of the hash, not the hash itself, from what I understand.
HV* hash = newHV();
...
use the hash
...
hv_undef(hash);
newHV
(like newSV
, newAV
, etc.) sets the reference count of the newly created value to 1. To free it, you just need to decrement it to 0. There's no special function for that for HVs, so just use SvREFCNT_dec
:
HV* hash = newHV();
/*
* use the hash
*/
SvREFCNT_dec((SV *) hash);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With