heap memory leakage

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

heap memory leakage

Postby XiotSamuel » Mon Oct 18, 2021 2:05 am

Hi all. I found that my program have a very serious memory leakage issue. I have try to use esp_get_minimum_free_heap check every function I can access, but still cannot found any part have memory leakage.

Is there have any way to check all variable and memory usage for the whole program?

I try to use the "Start Heap Trace" but cannot even start the debugger. Any suggestion for the heap memory checking? I am using VScode with esp-idf extension.

thanks

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Re: heap memory leakage

Postby XiotSamuel » Mon Oct 18, 2021 7:01 am

Hi, I am trying to run the esp_heap_trace.h and esp_heap_task_info.h on esp-mdf, but I found the make complier seem not recognise the heap_trace_record_t. I discover that the cmake file in the esp-idf and esp-mdf is very different. Will this effect the complier to get the data structure?

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Re: heap memory leakage

Postby XiotSamuel » Mon Oct 18, 2021 7:39 am

I have run the heap memory trace

and I found that the json components have many heap leakage. Is this normal?

Code: Select all

W (32327) [EnergysESP32FirmwareV1, 303]: <MDF_FAIL> mlink_httpd_write
D (32328) [EnergysESP32FirmwareV1, 321]: have type in the message
I (32141) mesh_mqtt: MQTT_EVENT_DATA, topic: Energys/TOPO/, data: {"addr":"94b97eacc648","data":{"type":"heartbeat", "self": "94b97eacc648", "parent":"e89f80587efb","layer":1}}
E (32354) [mesh_mqtt, 44]: mesh mqtt data start
D (32363) [EnergysESP32FirmwareV1, 337]: the free heap size is 39476 --root_write_task(end)
22 allocations trace (100 entry buffer)
6 bytes (@ 0x3fff3470) allocated CPU 0 ccount 0x343023cc caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

8 bytes (@ 0x3fff3f7c) allocated CPU 0 ccount 0x343049d4 caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff3fe0) allocated CPU 0 ccount 0x34306794 caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

6 bytes (@ 0x3fff3f98) allocated CPU 0 ccount 0x34308670 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

14 bytes (@ 0x3fff401c) allocated CPU 0 ccount 0x3430a5fc caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff4040) allocated CPU 0 ccount 0x3430c480 caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

8 bytes (@ 0x3fff407c) allocated CPU 0 ccount 0x3430e378 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

14 bytes (@ 0x3fff4098) allocated CPU 0 ccount 0x3431030c caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff40bc) allocated CPU 0 ccount 0x34312190 caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

6 bytes (@ 0x3fff40f8) allocated CPU 0 ccount 0x34314060 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

19 bytes (@ 0x3fff4114) allocated CPU 0 ccount 0x3431606c caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff413c) allocated CPU 0 ccount 0x34317f58 caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

10 bytes (@ 0x3fff4178) allocated CPU 0 ccount 0x34319e78 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

7 bytes (@ 0x3fff4198) allocated CPU 0 ccount 0x3431bdd0 caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff41b4) allocated CPU 0 ccount 0x3431dbe8 caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

19 bytes (@ 0x3fff41f0) allocated CPU 0 ccount 0x3431fbc8 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

5 bytes (@ 0x3fff4218) allocated CPU 0 ccount 0x34321ba4 caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

40 bytes (@ 0x3fff4234) allocated CPU 0 ccount 0x34323ddc caller 0x4013ee34:0x4013f66b
0x4013ee34: cJSON_New_Item at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:239

0x4013f66b: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1631
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

7 bytes (@ 0x3fff4270) allocated CPU 0 ccount 0x34325cc0 caller 0x4013e9e0:0x4013f68d
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f68d: parse_object at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1654
 (inlined by) parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1354

4 bytes (@ 0x3fff428c) allocated CPU 0 ccount 0x34327bb4 caller 0x4013e9e0:0x4013f43c
0x4013e9e0: parse_string at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:806

0x4013f43c: parse_value at /Users/esp32/esp/esp-idf/components/json/cJSON/cJSON.c:1339

1540 bytes (@ 0x3fff4484) allocated CPU 0 ccount 0x345dba18 caller 0x401568eb:0x401574a6
0x401568eb: mem_malloc at /Users/esp32/esp/esp-idf/components/lwip/lwip/src/core/mem.c:237

0x401574a6: pbuf_alloc at /Users/esp32/esp/esp-idf/components/lwip/lwip/src/core/pbuf.c:288

16 bytes (@ 0x3ffe9f90) allocated CPU 0 ccount 0x345e3abc caller 0x401568eb:0x4015695a
0x401568eb: mem_malloc at /Users/esp32/esp/esp-idf/components/lwip/lwip/src/core/mem.c:237

0x4015695a: do_memp_malloc_pool at /Users/esp32/esp/esp-idf/components/lwip/lwip/src/core/memp.c:254

1929 bytes 'leaked' in trace (22 allocations)
total allocations 59 total frees 40

willemmerson
Posts: 40
Joined: Mon Mar 18, 2019 12:34 pm

Re: heap memory leakage

Postby willemmerson » Mon Oct 18, 2021 8:01 am

Are you doing cJSON_Delete after creating json structures?

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Re: heap memory leakage

Postby XiotSamuel » Mon Oct 18, 2021 9:40 am

just check all cJSON_CreateObject have end with the cJSON_Delete.

Do I need to free any other type of JSON object?

I have char array in the program. Do I need to use free or MDF_FREE for the char array?

Who is online

Users browsing this forum: No registered users and 24 guests