简体   繁体   中英

android garbage collector information

I am writting an application that display a listView (with an image and some texts). I wrote my adapter, I recyle view and use a viewholder, all is working nice (but not very smoothly).

But by just having the listview displayed I can see in LogCat thousand and thousand of objects freed by the gc (~12000 every 3s ) It doesn't seems very normal too me.

在此处输入图片说明

Is there a way to know what is the class of the most gced object or some kind of logs (or stats) of the gc ? For me to understand why my application is spamming new objects that are immediately gced ?

This usually happens if you are downloading data - by your app or just any app. If not, you need to provide the code that is running so that we could have a look.

By the way, do something about your zero acceptance .

As I still can't comment, I add a new answer :-( It all depends what you do inside your adapter. You write you have XML data. You do the parsing inside? The DOM classes produce unbelievable amounts of garbage (and are slow as hell). If you have to parse DOM, do it outside the adapter and/or cache the results. Also, any enumeration you do (ex: for (String x : xarray) ) produces lot of garbage. Same for String operations (consider using StringBuilder). Try to not use function-local variables, put them into some more global scope (if not, its garbage). You display bitmaps? You create the Bitmap objects inside the adapter and then assign to the ImageView? Slow and lots of garbage, too.

I guess thats all of the common garbage and slow-UI-experience pitfalls. Anyone? ;)

Regards, Oliver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM