i have a custom list view. in that i am listing out images of around 200. The images are been stored in my drawable. I have converted the image to be a bitmap and i am displaying the image as bitmap. Every time when the activity is being opened the images get listed out. Like this when i am calling the activity for around 10 times it gets crashed and the error is
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
then i recycled the bitmaps and by using System.gs function i got the following
Clamp target GC heap from 25.464MB to 24.000MB
GC freed 322 objects / 70664 bytes in 146ms
Clamp target GC heap from 25.471MB to 24.000MB
GC freed 2 objects / 48 bytes in 138ms
Forcing collection of SoftReferences for 10720-byte allocation
Clamp target GC heap from 25.269MB to 24.000MB
DEBUG/dalvikvm(15311): GC freed 5080 objects / 211168 bytes in 121ms
ERROR/dalvikvm-heap(15311): Out of memory on a 10720-byte allocation
Now atlast i got this Out of memory on a 10720-byte allocation error
Now how to resolve the error, please help me friends
-
Can you avoid converting the images to bitmaps and refer to them instead by their resource IDs?Phillip Fitzsimmons– Phillip Fitzsimmons2011年08月12日 15:39:04 +00:00Commented Aug 12, 2011 at 15:39
-
1what do we mean by Clamp target GC heap fromCode_Life– Code_Life2012年12月10日 07:32:56 +00:00Commented Dec 10, 2012 at 7:32
2 Answers 2
Let's run through the checklist for your situation:
- Is a new activity created every time and you forget to finish out the previous one? If you did, make sure that you profile the app by dumping the memory in .hprof file and use MemoryAnalyzer (http://www.eclipse.org/mat/). Check the number of instances of activity that you have in memory to make sure that it is actually get cleaned up.
- If you are reloading the same data, you might want to keep this activity around and use FLAG_ACTIVITY_REORDER_TO_FRONT when starting it so it doesn't need to recreate
- How big is your drawable? You might want to resize it before you set it to your ImageView
Let me think up some more that might be helpful and add later
Comments
Have you tried setting the Bitmap variables as Soft-references?