Failed allocation for

I am testing my application and i find that it eventually shows…

Failed allocation for 16944 blocks, 203328 bytes

Does this mean too much memory is being used…is their any method to be able to monitor memory usage at runtime?

debug.print(debug.gc(false).tostring()); //not tested :slight_smile:

debug.gc(true) forces GC to run and will drive fragmented but available memory into contiguous blocks, and you may no longer fail (or delay your failure point). But a 203k block failing is a pretty big chunk of memory, are you expecting that large an allocation?

There is a limit on how large a single block of data can be.
it’s about 760kByte If I remember correctly.
And you have to be aware that if you have an array of objects, each item takes 12 Bytes (also if I remember correctly).

And even if you need a smaller block of data, this amount of data needs to be available as single block in RAM.
So if you do a lot of allocations and release the data afterwards, your RAM might get fragmented and you get this error even if there is enough RAM available.

By this you could create an byte[] with max 760000 items
or an int[] with max 190000 items
or an object[] with approx 63000 items

There is also an type called LargeArray, which is allocated in a different RAM segment, but this data is not affected by GC.
Never used it so far.