-->
Page 1 of 3

Memory Leak in ESP8266WebServer

PostPosted: Sun May 10, 2015 9:41 am
by ReinholdHiller
Latest files from githup, merged with appveyor 64Bit Build. Open the example, change handleroot():

Code: Select allvoid handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp8266!");
  digitalWrite(led, 0);

  Serial.print("Heap: ");
  Serial.println(ESP.getFreeHeap());
}


Open http://192.168.whatever in your browser and press "update" or whatever really reloads your webpage. I get something like this:

Heap: 28792
Heap: 27984
Heap: 28144
Heap: 28592
Heap: 28168
Heap: 27784
Heap: 27384
Heap: 26976
Heap: 26600
Heap: 26480
Heap: 26040
Heap: 25904
Heap: 25448
Heap: 25288
Heap: 24880
Heap: 25008
Heap: 24760
Heap: 24880
Heap: 24488
Heap: 24096
Heap: 24168
Heap: 23752
Heap: 23592
Heap: 23176


After some time, heap is at about 600 still going down, than watchdog reboot.

Any ideas?

Re: Memory Leak in ESP8266WebServer

PostPosted: Sun May 10, 2015 10:05 am
by andrew melvin
I would get this as well, have you tried leaving it a few minutes.

In my projects if i left it for a minute the heap would recover, back to normal.

Re: Memory Leak in ESP8266WebServer

PostPosted: Sun May 10, 2015 10:29 am
by ReinholdHiller
Addendum: I compiled it with the last github ESP8266WebServer soruces. Same result.

And I made a small change, doesn't change anything.

#ifdef DEBUG
DEBUG_OUTPUT.print("args count: ");
DEBUG_OUTPUT.println(_currentArgCount);
#endif

if (_currentArgs) delete[] _currentArgs;
_currentArgs = new RequestArgument[_currentArgCount];
int pos = 0;
int iarg;

Re: Memory Leak in ESP8266WebServer

PostPosted: Sun May 10, 2015 10:31 am
by ReinholdHiller
andrew melvin wrote:I would get this as well, have you tried leaving it a few minutes.

In my projects if i left it for a minute the heap would recover, back to normal.


I haven't.

And I think I can't wait with serving web pages to let the server recover because the web client is requesting data via Ajax every second or so to update some display...

To me it looks like that the problem is caused by the closing tcp connections that are their close-wait-state.

So, what to do if you want to server 1 or 2 connections per second over a period of time?