esp-idf: Ble Gatt Server Example Memory Leak When Connect/Disconnect (IDFGH-10930)
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
v5.0.3 and v4.3.5
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32 DEVKIT V1, Custom board with ESP32-WROVER
Power Supply used.
USB
What is the expected behavior?
Having the same free ram size after connecting and disconnecting the phone to ESP32.
What is the actual behavior?
I get lesser free ram size after connecting and disconnecting.
Steps to reproduce.
- Step: Start new project with “gatt_server” example
- Step: Add “while(1)” at the end of the main function and measure free internal ram size periodically
- Step: Open “nRF Connect” app on android
- Step: Find “ESP_GATTS_DEMO” device
- Step: Connect to device
- Step: Wait for 2-6 seconds
- Step: Disconnect from device
- Step: Repeat steps from 5.step a few times
Debug Logs.
I (27) boot: ESP-IDF v5.0.3-dirty 2nd stage bootloader
I (27) boot: compile time 15:01:11
I (27) boot: Multicore bootloader
I (30) boot: chip revision: v1.0
I (34) boot.esp32: SPI Speed : 40MHz
I (39) boot.esp32: SPI Mode : DIO
I (43) boot.esp32: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label Usage Type ST Offset Length
I (64) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (72) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (79) boot: 2 factory factory app 00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1ee48h (126536) map
I (145) esp_image: segment 1: paddr=0002ee70 vaddr=3ffbdb60 size=011a8h ( 4520) load
I (147) esp_image: segment 2: paddr=00030020 vaddr=400d0020 size=7e9b0h (518576) map
I (338) esp_image: segment 3: paddr=000ae9d8 vaddr=3ffbed08 size=030c4h ( 12484) load
I (343) esp_image: segment 4: paddr=000b1aa4 vaddr=40080000 size=17bd0h ( 97232) load
I (396) boot: Loaded app from partition at offset 0x10000
I (396) boot: Disabling RNG early entropy source...
I (407) cpu_start: Multicore app
I (407) cpu_start: Pro cpu up.
I (408) cpu_start: Starting app cpu, entry point is 0x400812c0
0x400812c0: call_start_cpu1 at C:/Users/hasan.demirtas/esp/esp-idf/components/esp_system/port/cpu_start.c:143
I (0) cpu_start: App cpu up.
I (426) cpu_start: Pro cpu start user code
I (426) cpu_start: cpu freq: 160000000 Hz
I (426) cpu_start: Application information:
I (430) cpu_start: Project name: gatt_server_demos
I (436) cpu_start: App version: 1
I (441) cpu_start: Compile time: Aug 22 2023 15:00:51
I (447) cpu_start: ELF file SHA256: 71e7ce467fb80dd8...
I (453) cpu_start: ESP-IDF: v5.0.3-dirty
I (458) cpu_start: Min chip rev: v0.0
I (463) cpu_start: Max chip rev: v3.99
I (468) cpu_start: Chip rev: v1.0
I (473) heap_init: Initializing. RAM available for dynamic allocation:
I (480) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (486) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (492) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (498) heap_init: At 3FFC6630 len 000199D0 (102 KiB): DRAM
I (504) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (510) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (517) heap_init: At 40097BD0 len 00008430 (33 KiB): IRAM
I (525) spi_flash: detected chip: generic
I (528) spi_flash: flash io: dio
W (532) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (546) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (672) BTDM_INIT: BT controller compile version [ad2b7cd]
I (672) system_api: Base MAC address is not set
I (672) system_api: read default base MAC address from EFUSE
I (682) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (1102) GATTS_DEMO: REGISTER_APP_EVT, status 0, app_id 0
I (1102) app_main: Free Internal Ram Size: 242428
I (1112) GATTS_DEMO: CREATE_SERVICE_EVT, status 0, service_handle 40
I (1112) GATTS_DEMO: REGISTER_APP_EVT, status 0, app_id 1
I (1132) GATTS_DEMO: SERVICE_START_EVT, status 0, service_handle 40
I (1132) GATTS_DEMO: ADD_CHAR_EVT, status 0, attr_handle 42, service_handle 40
I (1132) GATTS_DEMO: the gatts demo char length = 3
I (1142) GATTS_DEMO: prf_char[0] =11
I (1142) GATTS_DEMO: prf_char[1] =22
I (1152) GATTS_DEMO: prf_char[2] =33
I (1152) GATTS_DEMO: CREATE_SERVICE_EVT, status 0, service_handle 44
I (1162) GATTS_DEMO: ADD_DESCR_EVT, status 0, attr_handle 43, service_handle 40
I (1172) GATTS_DEMO: SERVICE_START_EVT, status 0, service_handle 44
I (1182) GATTS_DEMO: ADD_CHAR_EVT, status 0, attr_handle 46, service_handle 44
I (1182) GATTS_DEMO: ADD_DESCR_EVT, status 0, attr_handle 47, service_handle 44
I (2102) app_main: Free Internal Ram Size: 241636
I (3102) app_main: Free Internal Ram Size: 241636
I (4102) app_main: Free Internal Ram Size: 241636
I (5062) GATTS_DEMO: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 41:af:71:b4:0a:9b:
I (5062) GATTS_DEMO: CONNECT_EVT, conn_id 0, remote 41:af:71:b4:0a:9b:
I (5102) app_main: Free Internal Ram Size: 238492
I (5472) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400
I (5832) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 500
I (6002) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (6002) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (6082) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (6102) app_main: Free Internal Ram Size: 238492
I (7102) app_main: Free Internal Ram Size: 238492
I (8102) app_main: Free Internal Ram Size: 238492
I (9102) app_main: Free Internal Ram Size: 238492
W (9582) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x13
I (9582) GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (10102) app_main: Free Internal Ram Size: 240600
I (11102) app_main: Free Internal Ram Size: 240600
I (11952) GATTS_DEMO: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 4a:b3:f0:33:50:bd:
I (11962) GATTS_DEMO: CONNECT_EVT, conn_id 0, remote 4a:b3:f0:33:50:bd:
I (12102) app_main: Free Internal Ram Size: 238128
I (12372) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400
I (12732) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 500
I (12892) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (12892) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (12962) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (13102) app_main: Free Internal Ram Size: 238128
I (14102) app_main: Free Internal Ram Size: 238128
I (15102) app_main: Free Internal Ram Size: 238128
I (16102) app_main: Free Internal Ram Size: 238128
W (16482) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x13
I (16482) GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (17102) app_main: Free Internal Ram Size: 240252
I (18102) app_main: Free Internal Ram Size: 240252
I (19102) app_main: Free Internal Ram Size: 240252
I (19422) GATTS_DEMO: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 61:05:4a:53:aa:c5:
I (19432) GATTS_DEMO: CONNECT_EVT, conn_id 0, remote 61:05:4a:53:aa:c5:
I (19842) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400
I (20102) app_main: Free Internal Ram Size: 237796
I (20202) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 500
I (20372) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (20372) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (20442) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (21102) app_main: Free Internal Ram Size: 237796
I (22102) app_main: Free Internal Ram Size: 237796
I (23102) app_main: Free Internal Ram Size: 237796
W (23562) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x13
I (23562) GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (24102) app_main: Free Internal Ram Size: 239904
I (25102) app_main: Free Internal Ram Size: 239904
I (26102) app_main: Free Internal Ram Size: 239904
I (26182) GATTS_DEMO: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 76:43:d0:9c:f3:1c:
I (26182) GATTS_DEMO: CONNECT_EVT, conn_id 0, remote 76:43:d0:9c:f3:1c:
I (26592) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400
I (26952) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 500
I (27102) app_main: Free Internal Ram Size: 237448
I (27122) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (27122) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (27192) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (28102) app_main: Free Internal Ram Size: 237448
I (29102) app_main: Free Internal Ram Size: 237448
I (30102) app_main: Free Internal Ram Size: 237448
I (31102) app_main: Free Internal Ram Size: 237448
W (31212) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x13
I (31212) GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (32102) app_main: Free Internal Ram Size: 239556
I (33102) app_main: Free Internal Ram Size: 239556
I (33892) GATTS_DEMO: ESP_GATTS_CONNECT_EVT, conn_id 0, remote 6f:78:b6:da:08:10:
I (33892) GATTS_DEMO: CONNECT_EVT, conn_id 0, remote 6f:78:b6:da:08:10:
I (34102) app_main: Free Internal Ram Size: 237100
I (34302) GATTS_DEMO: update connection params status = 0, min_int = 16, max_int = 32,conn_int = 24,latency = 0, timeout = 400
I (34662) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 500
I (34832) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (34832) GATTS_DEMO: ESP_GATTS_MTU_EVT, MTU 500
I (34902) GATTS_DEMO: update connection params status = 0, min_int = 0, max_int = 0,conn_int = 24,latency = 0, timeout = 400
I (35102) app_main: Free Internal Ram Size: 237100
I (36102) app_main: Free Internal Ram Size: 237100
W (37002) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x13
I (37002) GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (37102) app_main: Free Internal Ram Size: 239208
I (38102) app_main: Free Internal Ram Size: 239208
I (39102) app_main: Free Internal Ram Size: 239208
I (40102) app_main: Free Internal Ram Size: 239208
More Information.
I was working on a project and i realised memory leak happens when i connect and disconnect with my phone. To generate this problem, i created a ble gatt server example. The only change i made is printing free internal ram space.
Any idea?
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 22
I had problems like that and I solved them, so I have responded to the issue with the solutions.
@zhp0406 I have just opened issue due to installation error. I will test memory leak problem after that. https://github.com/espressif/vscode-esp-idf-extension/issues/1032
@zhp0406 I am not able to test it with new environment today. I will try and give feedback to you next week;
@zhp0406 Can you repeat test with not ESP32C3 but ESP32?
@zhp0406 gatts_demo.txt