Heap Memory - Performance monitoring for the last 5 hours #825
Replies: 9 comments 38 replies
-
Have you watched it over several days? I ask, as I’ve seen this over a few hours at startup historically, but it generally stabilizes after a bit. I always attributed it to people walking past with BLE devices that scans pick up. |
Beta Was this translation helpful? Give feedback.
-
Hello again, 23 hours since the first gateway (esp32) startup: (From previous report) (The performance now is) 2024-12-28 09:40:21 --> ---- Heap Statistics ---- 2024-12-28 10:06:08 am --> ---- Heap Statistics ---- Any concern ? Will it leak memory over time ? I am concerned that esp will restart with lack of memory available after days. |
Beta Was this translation helpful? Give feedback.
-
Some more logs from the last couple of minutes: 2024-12-28 10:36:37 --> ---- Heap Statistics ---- |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello @h2zero, I could manage to use heap tracing in my nimBLE arduino code. I removed all AWS and WIFI connections and have run for couple of minutes. Min free heap has not started to decrease yet but look memory leakage from heap tracing: Look this part of the log: 23605 bytes 'leaked' in trace (88 allocations) It means that nimBLE is leaking memory during allocations and thats why I am facing min free heap drops over time., isn´t it? Every scan cycle this leakage memory is presented. I also removed 3 sensor servers from connection to see if it is caused by amount of sensors but I see same leaked in trace message every scan time. Any guess? Look my code attached, it is the standard code with quite few modifications just to track 4 well kwon devices. |
Beta Was this translation helpful? Give feedback.
-
I can see that your testing is flawed, you were checking for leaks before freeing the resources. |
Beta Was this translation helpful? Give feedback.
-
After implementing the delete client suggested: Same behavior has been visualized: |
Beta Was this translation helpful? Give feedback.
-
Hello all, now I have a more clear picture about the memory leakage after adjusting the heap trace stop in the code to avoid false positive. Now, the memory leakage seems more real to what happens to my application, that drains the memory over time. If we see, every cycle some bytes are leaked by 200 bytes: Therefore, these are the following elements reported in heap tracing: 2025-01-20 15:59:10 --> 6 allocations trace (500 entry buffer) I have used the xtensa do detect from which part of the code: Respective 0x40115945 and 0x400d2752 (Left side caller)PS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x40115945 PS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d2752 0x400d34d9PS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d34d9 0x400d336cPS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d336c 0x400d32a6PS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d32a6 0x400d40eaPS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d40ea 0x400d4022PS C:\Users\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d4022 0x400d2795PS C:\Users\poaand29\Documents\PlatformIO\Projects\Teste2> ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line -pfiaC -e .pio/build/esp32dev/firmware.elf 0x400d2795 |
Beta Was this translation helpful? Give feedback.
-
Hello, one update regarding to the heap results. I noticed based on my last assessments that there were some services or characteristics still persisted on memory. Therefore I added deleteServices method before deleting the Client to completely delete the client.
Running my application again, I have faced now only 1 allocation remaining with only 60 bytes. I am not able so far to detect what is this address using xtensa because it has given something that the editor cannot display like "???? : ?? : ? ". But see the allocations now:
With 60 bytes per scan cycle my gateway will work longer but still draining memory and overtime it will reset. I reset my application again and checked once more. I have noticed that now the allocation goes with different caller address 0x401158fd:0x400d349d consuming 60 bytes instead of previous 0x40115961:0x400d34ed:
The xtensa result for caller caller 0x401158fd:0x400d349d is:
The respective nimBLEDevice line 304 is:
I made sure all created clients are deleted. So, it is probably something related to internal nimBLE allocations. |
Beta Was this translation helpful? Give feedback.
-
Hello, first of all I would like to share that I am really happy with this library, its is awesome to handle BLE connections with stable performance. I was at the beggining strugglinh with arduino standard BLE library but failing all the time due to the memory leake. Now, things are much better. I can handle 4 BLE connections at time with no issues.
I do have a gateway (esp32 wroom32e) scanning 4 bluetooth devices sensors (servers, esp32 c3), servers advertises for 4 seconds and transmit data to gateway every 25 seconds. Code is pretty much the same presented for nimBLE Client.ino.
I have run a test and I have plotted the serial monitor every scan time, in addition to that adding memory information such as esp_get_free_heap_size() and esp_get_minimum_free_heap_size().
Below it is possible to see memory heap for the last 5 hours. Although heap memory variation is small and it cleary shows (when ploggin every second) a memory recovery when disconnecting and reconnecting devices, I still see it decreasing a litle bit over the hours. Is there any reason to concern about memory leake under this current scenario ? In case i run my device with this below´s performance, will it run out of memory over the weeks or months ?
2024-12-27 10:00 am --> ---- Heap Statistics ----
2024-12-27 10:00 am --> Free Heap: 206068 bytes bytes
2024-12-27 10:00 am --> Minimum Free Heap: 205656 bytes bytes
2024-12-27 1:00 pm --> ---- Heap Statistics ----
2024-12-27 1:00 pm --> Free Heap: 200016 bytes
2024-12-27 1:00 pm --> Minimum Free Heap: 199120 bytes
2024-12-27 2:00 pm --> Free Heap: 199776 bytes
2024-12-27 2:00 pm --> Minimum Free Heap: 199084 bytes
2024-12-27 2:00 pm --> -------------------------
2024-12-27 3:00 pm --> ---- Heap Statistics ----
2024-12-27 3:00 pm --> Free Heap: 200140
2024-12-27 3:00 pm --> Minimum Free Heap: 199084 bytes
2024-12-27 3:00 pm --> ------------------------
2024-12-27 4:00 pm --> ---- Heap Statistics ----
2024-12-27 4:00 pm--> Free Heap: 199672 bytes
2024-12-27 4:00 pm--> Minimum Free Heap: 199084 bytes
2024-12-27 4:00 pm --> -------------------------
Beta Was this translation helpful? Give feedback.
All reactions