简体   繁体   English

android垃圾收集器信息

[英]android garbage collector information

I am writting an application that display a listView (with an image and some texts). 我正在编写一个显示listView(带有图像和一些文本)的应用程序。 I wrote my adapter, I recyle view and use a viewholder, all is working nice (but not very smoothly). 我写了我的适配器,我重新使用视图并使用了一个Viewholder,一切都很好(但不是很顺利)。

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. 但是通过仅显示listview,我可以在LogCat中看到gc释放的成千上万个对象(每3s大约12000个)对我来说也不是很正常。

在此处输入图片说明

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 ? 有没有办法知道最接近对象的类或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. 我仍然无法发表评论,我添加了一个新答案:-(这完全取决于您在适配器内部所做的事情。您编写了XML数据。在内部进行了解析?DOM类产生了令人难以置信的大量垃圾(并且如果您必须解析DOM,请在适配器之外进行解析和/或缓存结果。此外,您所做的任何枚举(例如: for (String x : xarray) )都会产生大量垃圾。 (考虑使用StringBuilder。)尝试不使用函数局部变量,将它们置于更多的全局范围内(如果不是,则将其置于垃圾范围)。显示位图?在适配器内部创建位图对象,然后分配给ImageView?慢还有很多垃圾

I guess thats all of the common garbage and slow-UI-experience pitfalls. 我想这就是所有常见的垃圾处理和缓慢的UI体验陷阱。 Anyone? 任何人? ;) ;)

Regards, Oliver 问候,奥利弗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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