I've this code:
#include <stdio.h>
#include <unistd.h>
#include <json/json.h>
#include <stdio.h>
json_object *new_array;
void add_result_event(json_object *scan_result) {
json_object_array_add(new_array, scan_result);
}
void add_scan_result() {
json_object *scan_result = json_object_new_object();
json_object_object_add(scan_result, "ssid", json_object_new_string("ssssssssssssssssssssssssssssiiiiiiiiiiiidddddddddd"));
add_result_event(scan_result);
}
void alloc_object() {
int i = 0;
while (i < 100000) {
add_scan_result();
i++;
}
}
int main() {
new_array = json_object_new_array();
printf(" not started.. see memory\n");
system("ps -aux | grep sonj");
sleep (1);
alloc_object();
printf(" allocated.. see memory\n");
system("ps -aux | grep sonj");
sleep (1);
json_object_put(new_array);
printf(" freed.. see memory\n");
system("ps -aux | grep sonj");
sleep (1);
new_array = json_object_new_array();
printf(" allocated.. see memory\n");
alloc_object();
system("ps -aux | grep sonj");
sleep (1);
}
Compiled with:
~$ gcc json_array_obj_d.c -ljson-c -o sonj
Then, ran with:
~$ ./sonj
The VSZ field of output is not showing any memory freed to system after the json_object_put call
.
So freeing with json_object_put
does not give the memory to system, but next allocation also does not take more memory to system.
After json_object_put
is called when the free memory shows up in system?