Do I need to decref for each member or is it enough to decref root?

28 views
Skip to first unread message

Sadeep Madurange

unread,
Oct 9, 2022, 4:23:15 AM10/9/22
to Jansson users
Apologies if this question has been asked before. I couldn't find an answer searching here or the doc. If I have a root object and an array member containing string values. I get string values from the array and copy them to my own strings by looping the array.

My question is, at the end of this copying, should I call decref for each item in the array, or can I just call decref at the end of the function on root? Will it cleanup everything in it?

Petri Lehtinen

unread,
Oct 9, 2022, 1:11:35 PM10/9/22
to jansso...@googlegroups.com
You should only decref the root. It “owns” the contained values and will manage their refcounts. 

Petri


Sadeep Madurange <sadeepm...@gmail.com> kirjoitti 9.10.2022 kello 11.23:


Apologies if this question has been asked before. I couldn't find an answer searching here or the doc. If I have a root object and an array member containing string values. I get string values from the array and copy them to my own strings by looping the array.

My question is, at the end of this copying, should I call decref for each item in the array, or can I just call decref at the end of the function on root? Will it cleanup everything in it?

--
--
Jansson users mailing list
jansso...@googlegroups.com
http://groups.google.com/group/jansson-users
---
You received this message because you are subscribed to the Google Groups "Jansson users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jansson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jansson-users/f672bbcc-8557-45cd-9b00-c0faab3cfcabn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages