-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
2.4.1 memory leak #4497
Comments
Yes that code https://blog.thesen.eu/wp-content/uploads/2017/05/ESP_TH_Logger_V2.zip - A Temperature Logger for ESP8266 ( https://blog.thesen.eu/wlan-lufttemperatur-und-feuchte-logger-mit-grafischer-darstellung-fuer-esp8266/ ) works perfect with 2.3.0 but 2.4.0 do not work... every time load the site it eats free RAM until RAM gets out and no working any more. With 2.4.1 it is worser and the pages are not every time reachable and eating RAM every page refresh into dead faster. but when i enter 2.3.0 work best |
Sorry, I meant to say 2.3.0 is the best, not 2.4.0. |
No, @reaper7 in my case this does not improve anything... unfortunately. |
please check this simple sketch for show difference between global and local client declaration and memory leak when global...
if client is declared inside loop, then memory is reduced every loop by the first 17 connections
but if client is declared globally at top of sketch, then memory is reduced much more every loop by the first 17 connections and from connection number 18 never stop and consumes 56bytes per loop
|
@reaper7 Dear friend, I followed your suggestion to put inside the related function the "WiFiClient client;" so it is not global and the result is way better. In this case I loose 4*168 bytes + 424 bytes but then the leakage stopped... My project still under testing but your suggestion and analysis drove me to the right direction. Thanks a lot. |
Note: this sounds like something not being freed in WiFiClient::operator=() |
Will make a PR later today. |
Dear @igrr |
Created #4516 with a fix. Workaround for 2.4.1: client = WiFiClient(); // add this line for 2.4.1
client.connect(host, port); |
Milestoned as 2.5.0, but this might justify releasing 2.4.2 along with some other fixes. |
@igrr, I can add this:
to my own code but how do this when external library like pubsubclient is used,
|
Do you have a line in your sketch where you call client.connect? Then add espClient = WiFiClient(); before that line, I think it should work. The only case when it doesn't work is when the library reconnects automatically. Yes, this is not a perfect workaround. |
so, at this moment, completely correct "client" operation without editing external libs is not possible? |
In general case, no, not possible. However if you need to use 2.4.1 with PubSubClient, the workaround is applicable. void loop() {
if (!client.connected()) {
espClient = WiFiClient(); // workaround
reconnect();
}
client.loop(); If you are using git version, you can also do |
My last question :) |
Yes, this is just a workaround if you are having this issue and need to use 2.4.1. |
@igrr Does this also fix WiFiClientSecure as well? Looks like edits are only to WiFiClient. Edit: WiFiCientSecure does call WiFiClient. Just making sure. |
WiFiClientSecure should have the same issue (and same fix) because it uses the WiFiClient::connect() to initiate the actual TCP-level connection. It's worth trying his fix, if you can do so... |
How would I apply this fix for a re-entrant function, e.g.
edit: maybe do it with pointers ? Create a client with new() before TX and delete it after RX ? |
See described work-around in esp8266/Arduino#4497 (comment)
FWIIW , after getting rid of all Strings in my code and only using char arrays, I got down to having the 56 byte leak/call, which got me to this thread. |
I had the same problem. My program connects every minute to a server and writes some data (temperature and time) to it. Kept running out of memory and crashing. After declaring the client local, a test run of 1500 iterations shows me that Freeram keeps varying between 43K and 32K when the program does nothing else. I can live with that. Still wondering what happens though. Paai |
@paal This is a bug in 2.4.1 fixed in latest git version. |
Now I am confused. In the library manager of the Arduino IDE I see the esp8266wifi library of Ivan Grothotkov version 1.0.0 and here you are talking about 2.4.1. Is this the same library, and is the Arduino IDE just not up to date? Or is 2.4.1. a different animal? I'd rather not mess up my system, now that things are working nicely. Paai |
I must be confused, but before using ST_Anything, I didn't seem to have this leak, I didn't see it in the console of any of my units, and they've been running for months without issue. I just got into ST_Anything yesterday, and noticed the memory leak happening, and just cloned the repository yesterday, so I know I have all the latest libraries and sketches. So I am not sure what I need to downgrade in order to fix this memory issue, specifically? I checked what libraries I have installed, and I saw nothing pertaining to "2.4" and WiFi... (basically, same thing @paai commented on). Otherwise, awesome product you have here, really enjoying it! |
Okay, figured it out...it's the board manager version, not a library version. @paai - in Arduino, Tools -> Board -> Boards Manager, "esp8266 by ESP8266 Community". It'll show you have 2.4.1 installed, select 2.3.0 and install it, then recompile and upload your sketch. |
Ryanfort, Thanks for posting that. I have been tracking a memory leak in my program for a week. It was loosing 56 bytes every 30 seconds or so and crashing in 6 hours. Downgraded my "esp8266 by ESP8266 Community" board from 2.4.1 to 2.3.0 and it all went away! It is all now stable! |
Can somebody please explain what is happening here and why a permanent fix is not possible? If downgrading to 2.3.0 solves the problem, why 2.4.1 cannot be updated to incorporate the fix? |
@dccharacter I invite to look at the labels for this issue, where you will notice that this issue is already staged for release, which means it is already fixed. I invite you to then look at the milestones, where you will notice that this issue is targeted for release 2.4.2. If you investigate the milestones for 10 seconds, you can find out that release 2.4.2 is targeted for 1/Aug, which means it hasn't happened yet. |
Thanks for explanation! I just read through the thread and that wasn't clear. |
- ...fixed in 2.4.2 - Original Issue was: esp8266/Arduino#4497
- ...fixed in 2.4.2 - Original Issue was: esp8266/Arduino#4497
Today I noticed 2.4.1 was released for my Arduino IDE so I gave it a try. Unfortunately my app crashed after a few minutes. Memory pressure is always a good first guess so I added calls to ESP.getFreeHeap() and sure enough, the heap was smaller after each wifi client reconnection. It started at about 32000 bytes and dropped by a few kB each time. When the heap reached a few hundred bytes it paniced.
This was using lwip 2 for higher bandwidth. lwip 2 for lower memory acts the same way. I tried using lwip 1.4 forbandwidth but can't tell about the leak because it just flat fails to connect after a few connections.
My app is about 850 kB program and 45 kB RAM and not easy to post here. Basically it opens several web connections in a round robbin fashion, calling ::stop after finished with each. I noticed in the 2.4.1 release notes that ::stop no longer destroys ClientContext so I wonder if this might be related.
2.4.0 with lwip 1.4 precompiled is still the golden combo for me, it runs beautifully forever.
Thanks.
The text was updated successfully, but these errors were encountered: