The ESPMailer.cpp 'send()' method does not free up buf, and leaks quite a bit more than its 100 bytes on each send. I've been working on clearing up these leaks both within this library and WiFiClient and WiFiClientSecure methods.
For WiFiClient and WiFiClientSecure
These methods like being stopped, and while I haven't diagnosed which commands are effective, here is my belt-and-braces approach:
WiFiClientSecure wifiClientSecure; // use WifiClientSecure for HTTPS, WifiClient if HTTP
...
...
...
//Disconnect
wifiClientSecure.flush(); // may not be required
wifiClientSecure.stop();
delay(1000); // may not be required
yield(); // may not be required
I added this code to the following...
For EspMailer:
in 'send()' I replaced each occurrence of return false; with:
{
free(buf);
return false;
}
Modified end of method:
if (do_debug >= 0)
{
Serial.println("Email send complete");
}
free(buf);
_smtp.flush();
_smtp.stop();
delay(1000); // may not be required
return true;
In calling method
One last thing, undocumented but defined in ~ESPMailer(), is the cleanup for all other variables added to the heap by the library. Add delete(espMailer); at end of send routine to free up these resources. The complete method is shown as example:
The ESPMailer.cpp 'send()' method does not free up buf, and leaks quite a bit more than its 100 bytes on each send. I've been working on clearing up these leaks both within this library and WiFiClient and WiFiClientSecure methods.
For WiFiClient and WiFiClientSecure These methods like being stopped, and while I haven't diagnosed which commands are effective, here is my belt-and-braces approach:
I added this code to the following...
For EspMailer: in 'send()' I replaced each occurrence of
return false;
with:Modified end of method:
In calling method One last thing, undocumented but defined in
~ESPMailer()
, is the cleanup for all other variables added to the heap by the library. Adddelete(espMailer);
at end of send routine to free up these resources. The complete method is shown as example:Hope this will help anyone experiencing memory leaks. If there is a sexier way to do this I'd like to know.