Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Borisw37
#66812 I seem to have a memory leak which causes the processor to crash.
Using ESP8266 (NodeMCU) board.

I've cut my code down to bare minimum to demonstrate the issue.
Application prints out loop count and free heap size.
Starts with: "LoopCount: 1, FreeHeap: 47152"
Ends with: "LoopCount: 255, FreeHeap: 416"

After that there are some crash report messages:
Code: Select allException (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys
sp: 3ffffd70 end: 3fffffb0 offset: 01a0


Then the processor hangs and eventually resets.

Code: Select all#include <ESP8266WiFi.h>

// WiFi settings
const char* ssid     = "SSID";
const char* password = "PASSWORD";

// CherryPy Server Access
const char* myServer = "192.168.2.4";

void setup() {
 Serial.begin(250000);
 WiFi.disconnect();
 WiFi.mode(WIFI_STA);
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
}

int loopCount = 0;

void loop() {
 String POSTrLine;
 WiFiClient client;
 loopCount++;
 digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // Toggle RED led

 if(!client.connected()){
    if(client.connect(myServer, 80)){
     Serial.printf("New Connection to: %s\n", myServer);
    }
 }
 else {
   Serial.printf("Existing Connection to: %s\n", myServer);
 }

 while(client.available()){
   POSTrLine = client.readStringUntil('\r');
 }
 client.stop();
 Serial.printf("LoopCount: %u, FreeHeap: %u\n", loopCount, ESP.getFreeHeap());
}
User avatar
By Borisw37
#66823
rudy wrote:I am not a programmer. I don't know the ins and outs. But I think the problem is this.

WiFiClient client;

I think you want it out of the loop. Put it before setup.


I've tried that before with the same result. I thin the idea of it being in the loop is that memory gets released from the "client" class at the completion of loop (this obviously doesn't happen in this case).