Android Outofmemory When Gc Reports Free Memory?
Solution 1:
It seems your bitmap is allocating more than the available heap size. You can always monitor your memory usage using Eclipse MAT or android studio.
I suggest you to scale down your bitmap if they are larger than required. Also use options.inJustDecodeBounds = true to ensure your app is not kicked off from memory because of bitmap allocation. try to free resources what your app is not displaying. For free memory onPause call is a good place.You should also use GC call efficiently if needed. Also you can use
Drawabledrawable= imageView.getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawablebitmapDrawable= (BitmapDrawable) drawable;
Bitmapbitmap= bitmapDrawable.getBitmap();
bitmap.recycle();
}
to free the resource from your imageViews.
You can also set largeHeap="true". This actually force other app to out of memory. so how much heap will increase you never know. It depends on if any app was forced to get out of memory.
You have other option is create separate process so they will assign separately memory heap in your application. for this you have to use process="your process name" within activity tag.
Solution 2:
You need to understand a few things first.
- Android takes some time to grow the memory, and sometimes it's not fast enough. See https://stackoverflow.com/a/14462026/1390015.
- You need to load the bitmap into the right size. This will make your app faster and prevent consuming extra memory.
- You need to recycle your bitmaps.
I suggest you take a look at some Android image library like Picasso[http://square.github.io/picasso/]. It should do some of that work for you.
Post a Comment for "Android Outofmemory When Gc Reports Free Memory?"