puuu / ESPiLight

ESPiLight - pilight 433.92 MHz protocols library for Arduino
GNU General Public License v3.0
109 stars 41 forks source link

Possible memory leak when receiving #68

Open fredmaria opened 1 year ago

fredmaria commented 1 year ago

Hi, I think there may be a memory leak in EsPiLight. (I'm not an expert developer, so it could well be some kind of user error...) Here's a minimal code sample illustrating the problem I've encountered:

include

define RECEIVER_PIN 14 // any intterupt able pin

define TRANSMITTER_PIN -1

ESPiLight rf(TRANSMITTER_PIN);

void rfCallback(const String &protocol, const String &message, int status, size_t repeats, const String &deviceID) { Serial.printf("loop heap size: %u\n", ESP.getFreeHeap()); }

void setup() { Serial.begin(115200); Serial.println("Booting"); rf.setCallback(rfCallback); rf.initReceiver(RECEIVER_PIN); }

void loop() { rf.loop(); }

And here's the corresponding output: 15:16:55.473 -> loop heap size: 31496 15:17:41.075 -> loop heap size: 31136 15:17:41.174 -> loop heap size: 30776 15:17:41.240 -> loop heap size: 30416

........

15:22:57.536 -> loop heap size: 1256 15:23:33.932 -> loop heap size: 896 15:23:33.999 -> loop heap size: 536 15:23:34.065 -> loop heap size: 176 15:23:34.164 -> Out of memory. 15:23:34.164 -> EXIT: 1

The free heap size is decreasing until the microcontroller crashes.

In my case I'm using a nodemcu esp8266. I'm using Atom/PlatformIO.