OutOfMemory on loading thumbs in ListView

All your problems with Audio, Video and Images.

OutOfMemory on loading thumbs in ListView

Postby marlan » Sat Sep 26, 2009 8:33 am

Hi,

I am loading thumbnails in an ListActivity (with BaseAdapter).
I get the thumbnail urls from a webservice, it could be up to 600 thumbs (or more - depends on user input) at 3-4kilobytes .
The thumbnails are stored in an ArrayList as bitmaps.
When the user makes a new search, I iterate over the old result list and call bitmap.recycle(); and finally list.clear(). (So I don't think I am leaking any resources)
But after a few searches I frequently get an OutOfMemoryErrror: bitmap size exceeds VM budget.
How can I fix it?
I thought about saving the thumbs on sdcard and only load in the BaseAdapter
public View getView(int position, View convertView, ViewGroup parent) method.
Is this slow or battery consuming?
What is the best way to handle this?
Thanks
Mark
marlan
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 22, 2009 10:02 pm

Top

OOM with Bitmaps

Postby marlan » Sun Sep 27, 2009 9:56 am

I refactored my app, so that the bitmaps first saved to sdcard and then loaded into the listview when needed.
(I load max 30 thumbs in an Map, when I need more I clear the Map and call recycle on the old bitmaps)
But I still get an OutOfMemory error.
I noticed that the youtube google app also get an OOM (on my ADP1), when I make a repeated search with big results (and different keywords) and scroll through the whole result list:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. java.lang.OutOfMemoryError: bitmap size exceeds VM budget
  2.  
  3.  at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
  4.  
  5.  at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:308)
  6.  
  7.  at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:321)
  8.  
  9.  at com.google.android.youtube.VideoAdapter.getBitmapForVideo(VideoAdapter.java:261)
  10.  
  11.  at com.google.android.youtube.VideoAdapter.getBitmapAt(VideoAdapter.java:236)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

Is this an general android problem? Are bitmaps never released or only very slow?


Btw. should I expect an (usable) sdcard on the user phone? Is there a limit for the number of files in one folder?

Thanks Mark
marlan
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 22, 2009 10:02 pm

Postby marlan » Wed Sep 30, 2009 11:14 am

I think it was my fault, I missed some bitmap recycle calls.
I fixed it and so far I'd got no more OOM.
marlan
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 22, 2009 10:02 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests