I noticed a weird issue when doing a bunch of wifi configuration testing today. My firmware spits out available memory to serial, and after a bunch of cycles entering listening mode, configuring wifi, and restarting, the available memory was abnormally low. Each cycle would drop it by about 2k after that.
A hard reset cleared it up, but does entering listening mode from user firmware not reset the memory? It seems like I’d need a chance to free up memory before listening mode if so, but not sure if that’s at all viable. Thanks.
The docs does say that its not actually the amount of free mem, but at least this amount is free.
One way to estimate free memory on constrained devices is to paint a known value over the entire ram during boot, and then count how many cells still have that value, ie. never used, maybe something similiar is being used here.
I’ll have to do some more testing to see what happens as it approaches zero through more listening mode cycles. I understand it’s a minimum guarantee, not actual, but I know from fixing leaks I’ve caused that I’ve seen this reading approach zero, and the board eventually becomes unresponsive.
That’s exactly the kind of problem that System.freeMemory() was added to help highlight. If it approaches zero then most likely there is a memory leak somewhere. (Although you should rule out excessive memory usage as a cause.)
I made a couple attempts at testing this issue just now. The first time, freeMemory() was down to reporting 18k, when the softAP web API stopped responding. I had no way out of listening mode without a hard reset, so I di that and tried again.
This time, I got down to 23k, when it was stuck connecting to wifi, flashing green. I thought I put the credentials in incorrectly, but I couldn’t switch to listening mode from that state, so I reset, and it connected fine.
Overall, the memory drops inconsistently, often not at all, but sometimes by 22k in one cycle. I’ll make another try soon, but it’s not a very realistic scenario so I can’t spend too much time on it.