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. PV player intergration

Pls tell me where to get source code for PV player, PV multimedia
framework (PVMF) architecture, please provide me some link and docs.

How to build the OpenCore separately as part of the Android



2. Signed APK installed using a2b works / Same APK downloaded from market fails (force close)

We just released an update, and spent a considerable amount of time
trying to test. Once we released to the market, people started
complaining about it force closing.

The only way we were able to make it force close was by installing our
app by the market. (why would that change our app?) vs. installing by
adb as a signed app?

We also noticed that if you downloaded the app for the first time and
the newest version was 1.5.0, that the market forced 1.0 on you first,
then made you upgrade to 1.5.0, we resolved this by going to version
2.0, but what other alternative is there to avoid that upgrade path?



3. Saving layout state on configuration change

4. How to compile Android Project in to Jar file ?

5. How to Detect changes to a specific record through a content observer ?

6. Help with google uploader application

7. Is it possible to start my service automaticaly after phone boots up.