Memory leak in Gen3 network handling

Hi @nils ,
Thank you for your advice. I was using device OS 1.2.1. I tried using your code and also upgrading to 1.3.1, but I keep having connectivity issues: the device breaths cyan, even I made it log its connection to the cloud, which shows it's connected), but the device sometimes doesn't receive commands via Particle functions. Also, sometimes, I get the same error as you: [comm.protocol] ERROR: Event loop error 3 .

Regarding your suggestion about power supply, the current is fine (16A, but not sure about the spikes. I'll try to get the decoupling capacitors closer to the device, as now they are kind of close but connected by those jumper wires used for breadboards (maybe the wire length makes the distance too long?!).

I tried to get more logs to debug what's going on, however, even adding SerialLogHandler logHandler(LOG_LEVEL_ALL);, the serial monitor only showed the following message twice:

0000243138 [comm.protocol] ERROR: Event loop error 3
0000243139 [system] WARN: Communication loop error, closing cloud socket
0000243142 [system] ERROR: Failed to load session data from persistent storage

It didn't show any other messages, like you showed on your previous posts (like system, app, AT commands, etc). I tried updating the firmware via CLI, using particle update, in order to get the Device OS with DEBUG_BUILD=y (according to this post: MAJOR BUG in 1.0.1-rc.1 and 1.0.1 - #12 by rickkas7), but it didn't make a difference. Are you using any special configuration or code to have all those different logs printed to your serial monitor?

Thanks,
David