3

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

David Snabel-Caunt
58.4k13 gold badges118 silver badges132 bronze badges
asked Aug 12, 2011 at 15:30
2
  • Can you avoid converting the images to bitmaps and refer to them instead by their resource IDs? Commented Aug 12, 2011 at 15:39
  • 1
    what do we mean by Clamp target GC heap from Commented Dec 10, 2012 at 7:32

2 Answers 2

2

Let's run through the checklist for your situation:

  1. 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.
  2. 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
  3. 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

answered Aug 12, 2011 at 19:30
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried setting the Bitmap variables as Soft-references?

answered Aug 12, 2011 at 15:54

3 Comments

+1 but I think you need to explain a little more on what is soft-reference.
Basically you have a few types of references that you can declare a variable. One of them being Softreferences, another being WeakReferences. There are a couple more.. But I forget them off the top of my head. In general, what it does is declare when a variable will be collected by the garbage collector by giving it a certain hierarchy of the reference. Here is a good link giving a very clear description. A lot better than mine... References
The use of Java soft references is apparently not recommended for Android apps. See here developer.android.com/training/displaying-bitmaps/… and here stackoverflow.com/questions/11972441/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.