Reputation: 1215
This is one of the most asked question by beginners but still I couldn't get any help unfortunately. In an activity I have a viewflipper to which I assign imageviews with images programatically ( around 100 images added to viewflipper using for loop ). Might be due to image size or due to the large no of images I get OutOfMemory Error for bitmaps. My Questions are:
Please let me know if my question is confusing or is not understandable. This is an important topic to me as I am facing this problem in almost all my apps.
Upvotes: 1
Views: 1783
Reputation: 1923
Now what happens over here is every app in android is alotted a specific amount of heap size that is as little as 20mb
Bitmaps take up a lot of memory, especially for rich images like photographs
so whenever you load a heavy image or array of heavy images it exceeds the heap size and android automatically shuts down the app because it was using more than the allotted heap size
Read Documentaion
So whenever you are working with heavy images
Upvotes: 0
Reputation: 5152
to avoid,aquire large heap using this in manifest:
android:largeHeap="true"
and almost all problem solutions are present on these links related to memory out of error,hope that one of them may solve your problem:
Memory Leak and Out of memory Error using List,LinkedList and HashMap
Memory Leak and Out of memory Error using LRU Cache
Memory Leak and Out of memory Error using Disk LRU Cache
Upvotes: 4
Reputation: 16761
Bitmaps are handled by native memory. This means that when the GC collects the bitmap's reference, the bitmap's memory is not immediately removed. To clear the bitmap's memory immediately, you can call bitmap.recycle()
.
As for the ViewFlipper, you going to want to find a way to manually unload and reload images as they are displayed to the user. Remember to use recycle(), and don't try to display a bitmap that already was recycled.
Hope this helps :)
Upvotes: 1