android - ListView loading bitmap in viewholder raises memoryException -


i'm loading images in viewholder used in listview reuse layout of rows. after refreshing list couple of times memory exception. also, load bitmaps in size needed imageloader class, has worked correctly before that's not problem...

getview method of adapter:

public override view getview (int position, view convertview, viewgroup parent)     {         basebundelvo bundle = _bundles [position];         string celltype = getcelltype (bundle.type);          dsbundlelistitem holder=null;         view view = convertview;             if (convertview == null)          {             if (celltype == "dsbundlecell")              {                 holder = new dsbundlelistitem (_activity);                 view = _activity.layoutinflater.inflate (resource.layout.dsbundlelistitem, null);                 holder.iconiv = view.findviewbyid<imageview> (resource.id.iconiv);                 holder.coveriv = view.findviewbyid<imageview> (resource.id.coveriv);                 holder.bundleprogress = view.findviewbyid<progressbar> (resource.id.bundleprogress);                  view.tag = holder;             }         }         else         {             if (celltype == "dsbundlecell")              {                 holder = view.tag dsbundlelistitem;             }         }          holder.loadimage (bundle.coverimagelocation,bundle.icon);          return view;     } 

the getimage method of viewholder (called loadimage method):

public async void getimage(string originalimagelocation,string localimagelocation)     {         if (originalimagelocation == _iconimglocation)          {             iconiv.setimagebitmap             (             bitmap.createscaledbitmap (await imageloader.decodesampledbitmapfromresourceasync             (localimagelocation,(int)convertdptopix(30), (int)convertdptopix(30)), (int)convertdptopix(30), (int)convertdptopix(30), true)             );         }          if (originalimagelocation == _coverimglocation)          {             int screenwidth = _activity.resources.displaymetrics.widthpixels;             int imgwidth = screenwidth - (int)convertdptopix (32f);             int imgheight = (int)(convertdptopix(206f));              bundleprogress.visibility = viewstates.gone;              coveriv.setimagebitmap              (             bitmap.createscaledbitmap (await imageloader.decodesampledbitmapfromresourceasync             (localimagelocation, imgwidth, imgheight), imgwidth, imgheight, true)             );         }     } 

refreshing adapter:

handler in fragment contains listview:

void allbundelsloadedhandler (list<basebundelvo> bundels) {     list.onrefreshcompleted ();     adapter.setdata (bundels);     adapter.notifydatasetchanged (); } 

setdata method in adapter:

public void setdata(list<basebundelvo> bundles)     {         _bundles = bundles;     } 

output:

[monodroid] java.lang.outofmemoryerror [monodroid]     @ android.graphics.bitmap.nativecreate(native method) [monodroid]     @ android.graphics.bitmap.createbitmap(bitmap.java:810) [monodroid]     @ android.graphics.bitmap.createbitmap(bitmap.java:787) [monodroid]     @ android.graphics.bitmap.createbitmap(bitmap.java:719) [monodroid]     @ android.graphics.bitmap.createscaledbitmap(bitmap.java:595) [monodroid]     @ mono.java.lang.runnableimplementor.n_run(native method) [monodroid]     @     mono.java.lang.runnableimplementor.run(runnableimplementor.java:29) [monodroid]     @ android.os.handler.handlecallback(handler.java:733) [monodroid]     @ android.os.handler.dispatchmessage(handler.java:95) [monodroid]     @ android.os.looper.loop(looper.java:136) [monodroid]     @ android.app.activitythread.main(activitythread.java:5146) [monodroid]     @ java.lang.reflect.method.invokenative(native method) [monodroid]     @ java.lang.reflect.method.invoke(method.java:515) [monodroid]     @     com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:732) [monodroid]     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:566) [monodroid]     @ dalvik.system.nativestart.main(native method) 


Comments