What is your estimate of how long it takes to eat up the imp RAM? The imp004 and imp001 have different amounts of RAM. Additionally, you need contiguous space for arrays. A squirrel array is 36 bytes + 8 bytes per element (in the device, twice that in agent). Your filler of “123456789” doesn’t have the impact you imagine. It is allocated only once and each array element will simply reference it. Other issues to consider are:
the memory maps for imp001 and imp004 are different. The total RAM available doesn’t tell you how it’s fragmented.
the TCP buffer space is reclaimed when Wifi is dropped. When you reconnect, it will attempt to reallocate the space and may fail.
When the arrays are forced to resize, it may briefly use twice the RAM while it moves original array into a larger space.
I strongly recommend you put a debug port on your device that outputs text to tell you what is going on. A perfect way of testing this is to connect an imp to another imp. Send the imp state and the value from imp.getmemoryfree() out a UART that is received by the other imp.
you can use any method you prefer to fill up the RAM, i fulfill my purpose to make it “out of memory” with code above. the problem is when it’s happen while offline, my board completely freeze including the debug port.