I am getting a "bitmap size exceeds VM budget" error. I have read that there is a 16MB memory limit. In this thread Romain Guy says that "you can only allocate 16 MB of memory for your entire application".
However, my app must be running out of memory long before it reaches that limit. So my question is: how do I allocate memory to my application ... how can I get the allocation to my app increased (within the 16MB maximum)?
The Android Runtime (ART) and Dalvik virtual machine use paging and memory-mapping (mmapping) to manage memory. This means that any memory an app modifies—whether by allocating new objects or touching mmapped pages—remains resident in RAM and cannot be paged out.
The heap is what the memory manager uses to keep track of the memory. It consists of one or more unused memory areas, and all blocks of used memory. When the heap gets too low, it means that there is not enough free memory as the application is trying to use more memory than there is available.
In order to optimize the memory usage, Android tries to share some framework resources or common classes in memory across processes. So whenever a device boots up, a process called zygote loads the common framework code.
As with any Java VM, the heap memory will automatically grow to the max size. But, bitmaps are allocated outside the VM, so you don't "see" them easily in the stats. The best thing you can do is make sure you don't use large bitmaps, or scale them down using
http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html
From Eclipse you can generate a heap dump when you are on Android 1.6 or up and you can analyze the dump with Eclipse MAT.
Generally you can't control the max heap size on a real device, unless you are working with custom hardware or firmware.
There should be an article at developer.android.com on dumping the heap on 1.6, but I'm unable to find it. :(
Edit
Also, I have to mention that you can request more memory for applications by using
android:largeHeap="true"
in the manifest. But this is highly ill-adviced as most applications do not need this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With