Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear explanation of the OutOfMemoryError message

My Android app triggers an OutOfMemoryError like this:

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

Can anyone explain what each of those values mean ("byte allocation", "free bytes" and "until OOM")? The message is a little bit confusing for me.

Details: As far as I understand: there are 63MB until we get an OutOfMemoryError exception, we try to allocated 74649612 bytes but we have only 1048576 free bytes. (If we have "1048576 free bytes" how comes we have "63MB until OOM"? Do we have 63MB + 1048576 free bytes totally available and we are trying to allocated more than that, like 74649612 byte?)

like image 517
Alex Avatar asked Feb 08 '23 05:02

Alex


1 Answers

"Byte allocation" refers to how much memory you were trying to allocate in a single block. In this case, that is 74649612 bytes. This allocation request will fail most of the time.

"Free bytes" refers to how many bytes of free space are available on your heap without expanding the heap. In this case, that is 1048576 bytes. Note, though, that these "free bytes" may not be in a single contiguous block. Usually, this free space is fragmented into lots of smaller blocks.

"Until OOM" indicates that your heap could be expanded beyond its current size. Each process has a heap limit, based on device characteristics. In your case, the heap could be expanded by 63MB from its current size, up to the heap size limit. However, even that would not be big enough to give you a single contiguous free block of memory of the size that you are requesting.

like image 67
CommonsWare Avatar answered Feb 15 '23 23:02

CommonsWare