-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in a Wi-Fi connection and disconnection process (IDFGH-6820) #8446
Comments
hi @TakuyaAtMono , |
@MaxwellAlan |
@AxelLin @MaxwellAlan @TakuyaAtMono This is somehow in purpose, We didn't allocate the memory by use to reduce the allocate time when chip is go to sleep. The memory is shared by Wi-Fi and BLE, If we want to fix this bug, we need use Wi-Fi deinit and BT_deinit to free the memory. If you do think free the memory is necessary, we will consider add it. |
@jack0c -san, The RAM space cannot be effectively utilized due to the fact that memory is continually being allocated, and this is hindering the creation of our applications. Furthermore, it is difficult for not library engneer to identify the memory locations that are not being released one by one. Specifically (FYI, our development will not use BLE.) |
So if sleep functionality is disabled/unused, the allocation doesn't happen, right? |
OK, let's make sure two things:
|
@TakuyaAtMono are/were you using sleep functionality? |
I believe the problem is that the memory allocated at esp_wifi_init() and esp_wifi_connect() and that is not released at esp_wifi_disconnect() and esp_wifi_deinit(). As @jack0c wrote, "if both Wi-Fi and BLE deinit, free the memory" that is what I want. I hope the fix will be applied also to the ESP-IDF v4.4.1 release version not only the master verion of the IDF. |
I pressed the close button by mistake. Please ignore the status change. |
From what I understood from @jack0c's comment, the memory isn't deallocated so as to reduce the work performed at sleep/wake-up. That would make sleep relevant, were it not for the fact that you're not using it, I assume, based on your dismissal?! If that's the case, you're onto something and there is an issue since
isn't actually the case. |
@TakuyaAtMono This is merged into master(after 7a8b638), do you think it is OK? If it works for you, I can backport to IDFv4.4. You can cherry-pick it to have a try. |
@jack0c So, I copied only the changes made in 7a8b638 to ver4.1.1 and tried it, but the memory is not released. How can we try that the changes will be effective? |
@TakuyaAtMono Sorry, I didn't realize |
@jack0c And let me share the information what I tryed. I verified by using "Standalone Mode" of Heap memory debugging to connect to wifi (esp_wifi_init) and getting the leak status after disconnecting (esp_wifi_deinit). As I attached files "1372 bytes 'leaked' in trace (23 allocations)" is unchanged before and after applying "commit 7a8b638", so I think that the memory is not released. |
@TakuyaAtMono A mistake happen in s3. see cb0dd5c . I have merged the new one into master, and I also backport both of them to IDFv4.4, you can find it in b7d5e81. Please have a try. |
@TakuyaAtMono Thanks for reporting and sharing the updates. Would you please help check b7d5e81? Thanks. |
I'm seeing a memory leak from A test application I made to demonstrate this shows:
|
My example is a bit more complex but I can confirm that there is a memory leak in v5.1-dev-72.
After a number of loops through this the call will fail with ESP_ERR_NO_MEM |
Thanks for your feedback and sorry for late reply @aircable @bitmandu And it seems the different case for @dbahrdt. Could you please help provide your example so that we could reproduce your issue. |
Hi @Espressif-liuuuu , I guess you meant to mention someone else. |
Thanks for reporting, will close due to short of feedback, feel free to reopen with more updates. Thanks. |
I am experiencing this problem with ESP-IDF 5.1.4 and even with ESP-IDF 5.3.1 with an ESP32-S3. My device connects and disconnects from WiFi once every minute; this way it eats up ~180 kB of free memory in a day or less, causing the device to restart. What would it take to get this problem fixed? I'm happy to work on a reproducer, though it seems there is one already mentioned above. Is there some other way I can help? |
Hi @lptr , you can enable CONFIG_HEAP_TRACING_STANDALONE and use heap trace debug as the application below test application. 2 cases you can try
|
@Espressif-liuuuu Yep, I ran that, and I see the leakage. What should I do next? This is with an ESP32-S3:
|
Hi @lptr , sorry for late reply. The |
Hi @Espressif-liuuuu, just to clarify: these logs are coming from the test application you linked to above, not my own application. The test application only does connecting and disconnecting to WiFi, so it should come from there. I can run with a higher |
Maybe I confused you, I just hinted his code as an example to show how to use |
@Espressif-liuuuu thanks, I understand now what you meant! I'm still confused about how to proceed with this leak, though. IIUC, there is a memory leak in ESP-IDF when repeatedly connecting/disconnecting WiFi, as shown by the test application. Shouldn't then this issue be reopened, and the leak in ESP-IDF fixed? Or am I missing something? Is there perhaps that the test application does incorrectly, and some change could allow it to connect/disconnect WiFi repeatedly without leaking memory? |
Yes, if there is do some memory leak, we need to fix the issue. The example I shared, is not official CI test case but a demo by another developer in this issue, and it monitors the memory leak in one-time It seems that in your application, the memory are keeping decrease during multiple |
Do I understand correctly, that repeated calls to |
Yes! That it is. |
Hi @Espressif-liuuuu. I've finally managed to reproduce the problem using Arduino: espressif/arduino-esp32#10664. Do you think this is something on the |
Update: I tried it with Wokwi, and it seems that ESP-IDF indeed doesn't leak any memory upon repeated reconnects: https://wokwi.com/projects/415915821999976449 |
Hello,
I have created a Wi-Fi connection and disconnection process using the sample code "example_connect".
I used the heap_trace_init_standalone function to check for memory leaks before and after the connection, and found that the part shown in the attached file was leaking.
For example, there are some processes in the library that are allocated in esp-idf/components/esp_phy/src/phy_init.c:204 and then not released.
Can you please change these memory allocations so that they are released normally when Wi-Fi is stopped? Or please let me know how to handle this.
heapTrace.txt
The text was updated successfully, but these errors were encountered: