Java – Clear interpretation of OutOfMemoryError messages

Clear interpretation of OutOfMemoryError messages… here is a solution to the problem.

Clear interpretation of OutOfMemoryError messages

My Android app triggered an OutOfMemoryError:

java.lang.OutOfMemoryError: Failed to allocate a 74649612 byte allocation with 1048576 free bytes and 63MB until OOM

Can anyone explain what each value means (“byte allocation“, “free bytes“, and “until OOM”)? This message confused me a bit.

Details: As I understand it: there is still 63MB before the OutOfMemoryError exception, we try to allocate 74649612 bytes, but only 1048576 bytes are available. (If we have “1048576 free bytes”, why do we have “63MB until OOM”?) Do we have 63MB + 1048576 free bytes fully usable and we are trying to allocate more, say 74649612 bytes? )

Solution

“Byte allocation” refers to how much memory you are trying to allocate in a single block. In this case, it is 74649612 bytes. Such allocation requests fail in most cases.

“Available bytes” refers to how many free bytes of free space you have on your heap without expanding the heap. In this case, it is 1048576 bytes. Note, however, that these “free bytes” may not be in a contiguous block. Typically, this free space is split into many smaller blocks.

“Until OOM” indicates that your heap may expand beyond its current size. Depending on the characteristics of the device, each process has a heap limit. In your case, the heap can be expanded by 63MB from its current size until the heap size limit is reached. However, even this is not enough to give you a single contiguous free memory block of the size you requested.

Related Problems and Solutions