TCP Client Write Function

These maps:

 unordered_map<unsigned long, char*>         _incoming_responses;
 unordered_map<unsigned long, short>         _incoming_response_sizes;

It looks like you put data into the map, but not remove it? It’s a good idea to print the size of these maps also to see if they are indeed growing.

Keep in mind that System.freeMemory() is only a rough guide to the free memory (in 0.4.9 it is much more accurate.) So if your routine is leaking memory, it may not show until the heap needs to be expanded, which may happen in any other routine that needs memory. So, just because you see System.freeMemory() decrease, doesn’t mean that is where the leak is happening.

If you are using the local toolchain, please try the same against the 0.4.9-rc.2 release candidate - the improved resolution of System.freeMemory() will help you better pinpoint the memory leak.

It seems that this issue is either eliminated or greatly reduced in the newer system firmware. I tested with 0.4.8-rc.6 and devices have been working fine for the last 3 days, no more hanging and uptime has been greatly increased.