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?)


"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.


OutOfMemoryError

is the most common problem occur in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.

Read all 5 lessons and rewrite your code again. If it still don't work we will be happy to see what you've done wrong with the tutorial material.

Here some of possible answers for these type of errors in SOF

Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap

How to solve java.lang.OutOfMemoryError trouble in Android

Android : java.lang.OutOfMemoryError

java.lang.OutOfMemoryError

Solution for OutOfMemoryError: bitmap size exceeds VM budget

Please You Can Use The Image. and this image size very big that is problem. you can image size to resize

链接地址: http://www.djcxy.com/p/93068.html

上一篇: 由于createBitmap报告OOM,Monkey测试失败

下一篇: 清楚地解释OutOfMemoryError消息