On Nov 1, 2012 12:39 PM, "Da Beave" <dab...@gmail.com> wrote:
> {
> ..<snip>...
> /* Get data from the server */
> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); /* "response" storage the JSON response from the server */
> ..<snip>...
> json = json_tokener_parse(response);
>
> /* "cat" is the only thing I'm looking for at this time! */
>
> cat = json_object_get_string(json_object_object_get(json, "cat"));
>
> .. <snip - do some stuff with "cat"> ..
>
> free(json);
"free"? Is that a typo or are you really just calling the free() function? With json_object structures you need to use json_object_put() because it's more than just a flat block of memory.
Eric
Hi Da Beave,I am also facing same problem. I am using json_object_put(jsonobject) but it is not freeing the memory.is json_object_put() worked for you?ThanksVijay
On Friday, November 2, 2012 at ...
My code is thread based and like this:in one thread i am callingJSONobj = json_tokener_parse(chunk.memory);chunk.memory contains data which is downloaded using curl and is about 2MB of data.After this i am immediately callingjson_object_put(JSONobj);after this exiting the thread. but my memory is increasing when i call json_tokener_parse and after json_object_put, memory is not coming back.I have observed memory details in top command.
On Thu, Aug 23, 2018, 9:45 AM Vijay Maddula <mvijayk...@gmail.com> wrote:My code is thread based and like this:in one thread i am callingJSONobj = json_tokener_parse(chunk.memory);chunk.memory contains data which is downloaded using curl and is about 2MB of data.After this i am immediately callingjson_object_put(JSONobj);after this exiting the thread. but my memory is increasing when i call json_tokener_parse and after json_object_put, memory is not coming back.I have observed memory details in top command.That should work fine, but top is far too coarse of a tool to use to figure out what's going on. Can you run you test through valgrind to try to narrow down where the memory is leaking from?
Or, alternately, trim this down to a minimal test case that shows the problem? i.e. cut the threading, cut the curl, etc... and just hard code the contents of chunk.memory and the json-c calls.
LpI have attached a test-code(as you said) of my scenario here. As I have Observed Json is allocating memory for parsing, and after json_object_put It is not releasing memory to Heap and from next parsing onwards it is not creating any extra memory and is using the memory which is allocated at first time. And when Process exiting it is clearing all the memory. While process is executing json is not releasing the memory.
I ran valgrind and it shows 0 memory leaks. Valgrind giving results after process exited.So what i have to do to clear the total json allocated memory while executing a process.I have observed memory usage using top and htop commands also.
Hi Eric,If I run my code in a loop it will not increase the memory, This case already tested and mentioned in this thread.But in my case, once in a while i will only use huge amount of data. Remaining all the time it is very small amount of data. So my problem is whenever i get huge data, json is locking memory with its. So then remaining processes in the system will not run properly due to short ram. Json releasing data only when process exits but mine is continuous process. Thats the reason i want free the memory whenever i done with json data.
--