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

Moderator: igrr

User avatar
By pidloop
#87513 Hello! I am wondering how much free heap I should insure in my sketch. I have 3 WiFiClients and one WiFiServer open most of the time. ESP.getFreeHeap() always returns at least 12k, is that enough for sure? How does one tell? Thanks.
User avatar
By DIRR70
#87714 Hi pidloop,

I would say it depends ;)
Silly answer, isn't it? But you really can't say for sure.

If you are running a WiFi server you will most certainly build up some string to send stuff back to the browser. If you do so, you need twice as much free heap as you want to send. Twice? - Yes! You build up your string and then send it; by sending it all your data will be pushed to the IP stack and in that moment you need twice the space (even a little more, but not much). So, if you know how much data you'll send back you know roughly how many free heap you'll need.

But watch out! While the data is sent out to one client another client is able to request stuff and you need heap for that, too. With three clients accessing the chip at the same time it is really hard to say, how much free heap you'll need. Also you'll run into the problem of heap fragmentation (there are whole threads about that topic) - simply said, you will have multiple small blocks of free heap but none of them big enough to hold your data and so your code will fail.

If you are running out of heap (or having it fragmented to much) you'll experience that the browsers request will time out and not display what it usually does. So, the simplest way to test it out, is to let all your clients request whatever they usually request on and on and if they still get the proper response after several hours, your memory management is fine :)