Android OutOfMemory Within Different Devices ?
Solution 1:
Heap sizes vary by device. It is perfectly reasonable that on devices where apps have large heap sizes you will encounter fewer problems than on devices where apps have smaller heap sizes. Your heap could be as low as 16MB, if you are supporting older/lower-resolution devices.
Solution 2:
Most android has limited space. Usually 16MB. I highly suggest looking at your image size. Also use weak references where you can to make sure images are only using memory when accessed. (Weak references will force the garbage collected to clean them up quicker.)
- And I don't know much about your app with just your logcat error list, but if you have multiple activities, kill the ones you don't need. Might seem like obvious advice, maybe not, but it will free up space.
Solution 3:
As others stated, the heap size for an Application is limited. The minimum is 16MB and veries from device to device (it's a setting of the virtual machine).
Some suggestions what you could do:
- You can load a smaller version of the image, if not needed in full resolution. Here is how to do it: http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html
- Check if enough free memory is available; If memory gets low, you can just free images that are not directly needed right now and load them again, if they are needed.
Here is some code sniped for checking how much free memory is left:
long free = Runtime.getRuntime().freeMemory();
Solution 4:
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
that line says it all. The bitmaps are hogging all the memory of some devices (devices that the VM stack limit is higher). You should look into better memory management for this application such as LruCache, decode bitmaps with lower quality, etc.
edit: do not use WeakReference as some users might suggest. check this question Does Android need to load a complete Bitmap from a file before sampling it down? and also this video http://www.youtube.com/watch?v=gbQb1PVjfqM
direct explanations/teachings/techniques from the creators of the platform and say to not use WeakReference.
Post a Comment for "Android OutOfMemory Within Different Devices ?"