Am I leaking bitmaps from adapter's getView ?

by Alexey » Wed, 01 Apr 2009 09:41:54 GMT

Sponsored Links
 Hi All , I definitely have a memory leak problem and i'm trying to
figure out there. After 6-10 config changes i'm getting out of memory
in regards to  BitmapFactory.  I'm kind of suspect that this is going
on within adapter.
 I have a listview . ListItems are an thumbnail image ( ImageView )
and TextView for text.

Here is the getView code.

                                if (convertView != null )
                                        newView = convertView;
                                else {
                                        LayoutInflater layout = 
                                        newView = 
layout.inflate(R.layout.list_item, null);

                                TextView tView = (TextView) 


                                ImageView iView = (ImageView) 

                                Bitmap thumbnail = nItem.getThumbnailBitmap();
                                if (thumbnail != null) {

and get ThumbnailBitmap() is basically
BitmapFactory.decodeByteArray ..  Is it possible that i'm leaking
drawables ? Heap is not increasing by the way .

Am I leaking bitmaps from adapter's getView ?

by jefferyfry » Thu, 02 Apr 2009 08:15:22 GMT

 Are you recycling your bitmaps?  I'm not sure what your
getThumbnailBitmap is doing, but I have something that sounds similar
where I rescale my bitmaps like so:

        public static Bitmap getBitmap(Context context,String photoUriPath)
throws Exception {
                Uri photoUri = Uri.parse(photoUriPath);
                InputStream photoStream = context.getContentResolver
                BitmapFactory.Options options = new BitmapFactory.Options();
                Bitmap photoBitmap = BitmapFactory.decodeStream
                int h = photoBitmap.getHeight();
                int w = photoBitmap.getWidth();
                        double ratio = 128d/w;
                else if((h>w)&&(h>128)){
                        double ratio = 128d/h;
                Bitmap scaled = Bitmap.createScaledBitmap(photoBitmap, w, h, 
                return scaled;

I make sure I call recycle() on the original bitmap to conserve


Sponsored Links

Am I leaking bitmaps from adapter's getView ?

by Alexey » Sun, 12 Apr 2009 05:42:20 GMT

 thanks ! I'll go through my images again to make sure - but i found my
problem  data observer that i forgot to unregistered so now it's much


Other Threads

1. Can I use an AsyncTask instead of a Service for my Widget's background processing?

Just curious if there's any reason why I can't use an AsyncTask -- my
current implementation uses AsyncTask and I'm experiencing inconsistent
widget refreshing.



2. How to have a notification icon with image + text

I love when the same questions are asked over and over:

TreKing - Chicago transit tracking app for Android-powered devices


3. Continuous Speech Recognition?

4. Kernel module deployment

5. Intermezzo dulu ah boss ....

6. (WTA) Bluetooth Spica 1.5 status Paired but not connect

7. Looking for definitive location finding logic