Android Listview GC_FOR_ALLOC freed: DDMS android.graphics.Bitmap -
i'm having trouble listview in android. when start scrolling down list, slow , see gc called. when i'm @ bottom of list, works fine , smooth. think @ point viewholder work.
but can't find source calling gc. searched lead to:
ddms 436816 byte[] 1 android.graphics.bitmap nativecreate
i can't interpret line. arrayadapter
, it's getview
method looks this:
public class diagnoseadapter extends arrayadapter<visualizer> { @override public view getview(int position, view convertview, viewgroup parent) { int type = type_default; final visualizer item = getitem(position); switch(item.gettype()){ case type_default: convertview = defaulttextview.getview(position, convertview, mlayoutinflater, item, parent); break; // more cases/types } return convertview; } }
which calling following getview
method of class defaulttextview
public class defaulttextview{ public static view getview(int position, view convertview, layoutinflater layoutinflater, visualizer item, viewgroup parent){ viewholder holder; if (convertview == null || item.getreleatedobject() == null || convertview.gettag()!=tag_default) { convertview = layoutinflater.inflate(r.layout.diagnose_item, null); holder = new viewholder(); holder.value = (textview) convertview.findviewbyid(r.id.diagnose_function_value); holder.name = (textview) convertview.findviewbyid(r.id.diagnose_function_setname); holder.mlinlayout = (linearlayout) convertview.findviewbyid(r.id.default_linlayout); convertview.settag(tag_default); convertview.settag(r.layout.diagnose_item,holder); item.setreleatedobject(convertview); } else { holder = (viewholder) convertview.gettag(r.layout.diagnose_item); } holder.value.settext(item.tostring()); holder.name.settext(item.gettooltip()); holder.mlinlayout.removeallviews(); if (item.getupdateflag(4)) { if (holder.back == null){ holder.back = new imageview(convertview.getcontext()); holder.back.setscaletype(scaletype.fit_center); holder.back.setadjustviewbounds(true); holder.back.setimagebitmap(bm1); } holder.mlinlayout.addview(holder.back); } if (item.getupdateflag(1)) { if (holder.update == null){ holder.update = new imageview(convertview.getcontext()); holder.update.setscaletype(scaletype.fit_center); holder.update.setadjustviewbounds(true); holder.update.setimagebitmap(bm2); } holder.mlinlayout.addview(holder.update); } if (item.getupdateflag(2)) { if (holder.timer == null){ holder.timer = new imageview(convertview.getcontext()); holder.timer.setscaletype(scaletype.fit_center); holder.timer.setadjustviewbounds(true); holder.timer.setimagebitmap(bm3) } holder.mlinlayout.addview(holder.timer); } if (item.getupdateflag(3)) { if (holder.log == null){ holder.log = new imageview(convertview.getcontext()); holder.log.setscaletype(scaletype.fit_center); holder.log.setadjustviewbounds(true); holder.log.setimagebitmap(bm4); } holder.mlinlayout.addview(holder.log); } if (item.getupdateflag(0)) { if (holder.forward == null){ holder.forward = new imageview(convertview.getcontext()); holder.forward.setscaletype(scaletype.fit_center); holder.forward.setadjustviewbounds(true); holder.forward.setimagebitmap(bm5); } holder.mlinlayout.addview(holder.forward); } return convertview; } static class viewholder { textview name, value; imageview back, update, timer, log, forward; linearlayout mlinlayout; } }
even if comment linearlayout
out, have list 2 textviews
.
so question. miss anything. stupid thing? how listview smoother? btw: read in different thread, happening if listview
has attribute android:cachecolorhint="#00000000
. don't have attribute.
i hope has solution. thanks!
about source of gc calls. if i'm understanding code correctly, everytime listview items recycled , call removeallviews()
, dynamically created imageview
removed , bitmap
garbage collected. so, maybe gc calls avoided if use same imageview
declaring in xml layout , replace bitmap
according getupdateflag()
.
and 2 more things listviews , images. first thing if image big, listview going laggy no matter what. need scale image down if case( loading large bitmaps efficiently). , second, maybe need implement lazy list, loads images on demand, there famous question --> how do lazy load of images in listview?
Comments
Post a Comment