Regarding freeing the json objects.

2,471 views
Skip to first unread message

venkat

unread,
Jul 19, 2011, 7:09:44 AM7/19/11
to json-c
Hi All,

we are creating json object , json array object etc. how to free those
newly created objects.

eg:

my_array = json_object_new_array();

new_obj = json_object_new_object();

here my_array and new_obj are newly created ones . how to free these
objects.

My doubt is whether it leads to memory leak or not?


Thanks,
Venkat.

Eric Haszlakiewicz

unread,
Jul 19, 2011, 12:34:53 PM7/19/11
to jso...@googlegroups.com

If those do not get added to any other object, you need to call json_object_put() on each one.
On the other hand, if you *did* add them to a containing object, then the "ownership" of those objects has transferred over and you need to call json_object_put() on whatever your top-level object is.  That will free all children.

If you need the objects to stick around even after the top-level object is freed, you can manually increase the reference count with json_object_get(), but that is probably not something you want to do.

Eric

venkataragavan vijayakumar

unread,
Jul 20, 2011, 2:27:04 AM7/20/11
to jso...@googlegroups.com
Thanks Eric.. I have used json_object_put().

Regards,
venkat.

Pawel

unread,
Jun 30, 2012, 6:03:52 PM6/30/12
to jso...@googlegroups.com

Hi.

Sorry, folks, can't figure out how do I then delete the root object? :)

On Tuesday, July 19, 2011 9:34:53 AM UTC-7, Eric wrote:

Eric Haszlakiewicz

unread,
Jun 30, 2012, 10:18:11 PM6/30/12
to jso...@googlegroups.com


On Jun 30, 2012 5:03 PM, "Pawel" <pawel....@gmail.com> wrote:
>
> Sorry, folks, can't figure out how do I then delete the root object? :)

Like I said, call json_object_put() on the your top-level (aka root) object.

If you're having problems, please provide a small sample program that demonstrates the issue and we'll see what we can figure out.

Eric

Pawel

unread,
Jun 30, 2012, 11:40:55 PM6/30/12
to jso...@googlegroups.com

On Saturday, June 30, 2012 7:18:11 PM UTC-7, Eric wrote:


On Jun 30, 2012 5:03 PM, "Pawel" wrote:
>
> Sorry, folks, can't figure out how do I then delete the root object? :)

Like I said, call json_object_put() on the your top-level (aka root) object.

If you're having problems, please provide a small sample program that demonstrates the issue and we'll see what we can figure out.

Apologies again, the name just really confused me, should've read the docs for the function :)
Reply all
Reply to author
Forward
0 new messages