in reply to Re^2: XS: how to destroy HV* that was used internally?
in thread XS: how to destroy HV* that was used internally?

That's because SvREFCNT_dec already casts for you. In fact, it casts in a way that will detect if the input was const, so doing SvREFCNT_dec((SV*)hv) instead of SvREFCNT_dec(hv) is actually harmful.

If you ever use (SV*)x, consider using MUTABLE_SV(x) instead.