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 = 
LayoutInflater.from(mContext);
                                        newView = 
layout.inflate(R.layout.list_item, null);
                                }

                                TextView tView = (TextView) 
newView.findViewById(R.id.title);

                                tView.setText(nItem.Title);

                                ImageView iView = (ImageView) 
newView.findViewById(R.id.image);

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


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
().openInputStream(photoUri);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize=2;
                Bitmap photoBitmap = BitmapFactory.decodeStream
(photoStream,null,options);
                int h = photoBitmap.getHeight();
                int w = photoBitmap.getWidth();
                if((w>h)&&(w>128)){
                        double ratio = 128d/w;
                        w=128;
                        h=(int)(ratio*h);
                }
                else if((h>w)&&(h>128)){
                        double ratio = 128d/h;
                        h=128;
                        w=(int)(ratio*w);
                }
                Bitmap scaled = Bitmap.createScaledBitmap(photoBitmap, w, h, 
true);
                photoBitmap.recycle();
                return scaled;
        }

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



--~--~---------~--~----~------------~-------~--~----~


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
better.




--~--~---------~--~----~------------~-------~--~----~



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.

TIA!
PT

-- 

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




I love when the same questions are asked over and over:
http://developer.android.com/intl/fr/reference/android/app/Notification.html#number

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 

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