Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to free json_object?

Tags:

json

c

libjson

I have the following code

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

#include <json/json.h>

int main(int argc, char **argv)
{
      json_object *new_obj;
      char buf[] = "{ \"foo\": \"bar\", \"foo2\": \"bar2\", \"foo3\": \"bar3\" }";
      new_obj = json_tokener_parse(buf);
      .....
      json_object_put(new_obj);
}

Does the json_object_put(new_obj) free all memory related to new_obj ?

like image 826
MOHAMED Avatar asked Feb 14 '13 16:02

MOHAMED


1 Answers

From the documentation:

void json_object_put    (struct json_object *this)  

Decrement the reference count of json_object and free if it reaches zero

Source: http://oss.metaparadigm.com/json-c/doc/html/json__object_8h.html

like image 184
djechlin Avatar answered Sep 25 '22 02:09

djechlin