<bdo id='9WpvD'></bdo><ul id='9WpvD'></ul>

    1. <tfoot id='9WpvD'></tfoot>
    2. <i id='9WpvD'><tr id='9WpvD'><dt id='9WpvD'><q id='9WpvD'><span id='9WpvD'><b id='9WpvD'><form id='9WpvD'><ins id='9WpvD'></ins><ul id='9WpvD'></ul><sub id='9WpvD'></sub></form><legend id='9WpvD'></legend><bdo id='9WpvD'><pre id='9WpvD'><center id='9WpvD'></center></pre></bdo></b><th id='9WpvD'></th></span></q></dt></tr></i><div id='9WpvD'><tfoot id='9WpvD'></tfoot><dl id='9WpvD'><fieldset id='9WpvD'></fieldset></dl></div>
    3. <small id='9WpvD'></small><noframes id='9WpvD'>

      <legend id='9WpvD'><style id='9WpvD'><dir id='9WpvD'><q id='9WpvD'></q></dir></style></legend>

      列表视图中的大量垃圾收集

      时间:2023-05-19
    4. <small id='dECD6'></small><noframes id='dECD6'>

      <legend id='dECD6'><style id='dECD6'><dir id='dECD6'><q id='dECD6'></q></dir></style></legend>
        <tbody id='dECD6'></tbody>
          <bdo id='dECD6'></bdo><ul id='dECD6'></ul>
          • <tfoot id='dECD6'></tfoot>
              <i id='dECD6'><tr id='dECD6'><dt id='dECD6'><q id='dECD6'><span id='dECD6'><b id='dECD6'><form id='dECD6'><ins id='dECD6'></ins><ul id='dECD6'></ul><sub id='dECD6'></sub></form><legend id='dECD6'></legend><bdo id='dECD6'><pre id='dECD6'><center id='dECD6'></center></pre></bdo></b><th id='dECD6'></th></span></q></dt></tr></i><div id='dECD6'><tfoot id='dECD6'></tfoot><dl id='dECD6'><fieldset id='dECD6'></fieldset></dl></div>
              1. 本文介绍了列表视图中的大量垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个使用自定义适配器的 ListView.自定义适配器的 getView 使用所有推荐的做法:

                I have a ListView that uses a custom adapter. The custom adapter's getView uses all the recommended practices:

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    SuscriptionsViewsHolder holder;
                    ItemInRootList item = mItemsInList.get(position);
                
                    if (convertView == null) {
                         convertView = mInflater.inflate(R.layout.label, null);
                
                         holder = new SuscriptionsViewsHolder();
                         holder.label = (TextView) convertView.findViewById(R.id.label_label);
                         holder.icon = (ImageView) convertView.findViewById(R.id.label_icon);
                
                        convertView.setTag(holder);
                    } else {
                        holder = (SuscriptionsViewsHolder) convertView.getTag();
                    }
                
                    String text = String.format("%1$s (%2$s)", item.title, item.unreadCount);
                    holder.label.setText(text);
                    holder.icon.setImageResource(item.isLabel ? R.drawable.folder : R.drawable.file );
                
                    return convertView;
                }
                

                但是当我滚动时,由于垃圾收集繁重,它很慢:

                However when I scroll, it is sluggish because of heavy garbage collection:

                GC_EXTERNAL_ALLOC freed 87K, 48% free 2873K/5447K, external 516K/519K, paused 30ms
                GC_EXTERNAL_ALLOC freed 7K, 48% free 2866K/5447K, external 1056K/1208K, paused 29ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2866K/5447K, external 1416K/1568K, paused 28ms
                GC_EXTERNAL_ALLOC freed 5K, 48% free 2865K/5447K, external 1600K/1748K, paused 27ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2865K/5447K, external 1780K/1932K, paused 30ms
                GC_EXTERNAL_ALLOC freed 2K, 48% free 2870K/5447K, external 1780K/1932K, paused 26ms
                GC_EXTERNAL_ALLOC freed 2K, 48% free 2870K/5447K, external 1780K/1932K, paused 25ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 26ms
                GC_EXTERNAL_ALLOC freed 3K, 48% free 2870K/5447K, external 1780K/1932K, paused 25ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 29ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 29ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2871K/5447K, external 1780K/1932K, paused 28ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2871K/5447K, external 1780K/1932K, paused 26ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 27ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 29ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 26ms
                GC_EXTERNAL_ALLOC freed <1K, 48% free 2870K/5447K, external 1780K/1932K, paused 34ms
                

                似乎出了什么问题?

                编辑@12:47 GMT:

                EDIT @12:47 GMT:

                事实上,它比这稍微复杂一些.我的应用程序 UI 基于 2 个部分.一个是屏幕的大脑,创建视图,处理用户输入等.另一个是 Fragment 如果设备具有 android 3.0,否则它是 Activity.

                In fact it's slightly more complicated than this. My app UI is based on 2 parts. One is the brain of a screen, creating the views, handling user input, etc. The other is a Fragment if the device has android 3.0, otherwise it's an Activity.

                GC 发生在我的 Nexus One 2.3.3 设备上,因此使用 Activity.我没有带 Xoom 来测试 Fragment 的行为.

                The GC happened on my Nexus One 2.3.3 device, so using the Activity. I don't have my Xoom with me to test the behaviour with a Fragment.

                如果需要,我可以发布源代码,但让我尝试解释一下:

                I could post the source if required, but let me try to explain it :

                • RootList 是 UI 的大脑.它包含 :
                  • 将放置在 ListView 中的项目的 List<>.
                  • 从 SQLite db 构建此列表的方法
                  • 一个自定义的 BaseAdapter,基本上只包含上面粘贴的 getView 方法
                  • RootList is the brain of the UI. It contains :
                    • a List<> of items that will be placed in the ListView.
                    • a method that builds this list from a SQLite db
                    • a custom BaseAdapter that contains basically only the getView method pasted above
                    • 使用 XML 布局
                    • 布局当然有一个 ID 为 android.id.list
                    • 的列表视图
                    • Activity 回调被转发到 RootList 类,使用创建活动时创建的 RootList 实例(构造函数,而不是 onCreate)
                    • onCreate 中,我调用 RootList 的方法来创建项目列表,并将列表数据设置为我的自定义类派生自BaseAdapter
                    • uses an XML layout
                    • the layout has of course a listview with id android.id.list
                    • the Activity callbacks are forwarded to the RootList class using an instance of RootList created when the activity is created (constructor, not onCreate)
                    • in the onCreate, I call RootList's methods that will create the list of items, and set the list data to a new instance of my custom class derived from BaseAdapter

                    格林威治标准时间 5 月 17 日晚上 9:36

                    EDIT on may 17th @ 9:36PM GMT:

                    这是 Activity 的代码和执行这些操作的类.http://pastebin.com/EgHKRr4r

                    Here's the code of the Activity and the class that does the things. http://pastebin.com/EgHKRr4r

                    推荐答案

                    我发现了问题.我的活动 XML 布局是:

                    I found the issue. My XML layout for the activity was:

                    <?xml version="1.0" encoding="utf-8"?>
                    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
                    
                        <include android:id="@+id/rootlist_header" layout="@layout/pre_honeycomb_action_bar" />
                    
                        <ListView android:id="@android:id/list"
                            android:layout_below="@id/rootlist_header"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"
                            android:textColor="#444444"
                            android:divider="@drawable/list_divider"
                            android:dividerHeight="1px"
                            android:cacheColorHint="#00000000" />
                    
                    </RelativeLayout>
                    

                    如果我删除 android:cacheColorHint="#00000000",重 GC 出来了,滚动是 smooth!:)

                    If I remove the android:cacheColorHint="#00000000", the heavy GC is out, and the scrolling is smooth! :)

                    我真的不知道为什么要设置这个参数,因为我不需要它.也许我复制粘贴太多,而不是实际构建我的 XML 布局.

                    I don't really know why this parameter was set, because I don't need it. Maybe I copypasted too much instead of actually build my XML layout.

                    感谢您的支持,非常感谢您的帮助.

                    THANK YOU for your support, I really appreciate your help.

                    这篇关于列表视图中的大量垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:android - GC_FOR_ALLOC 释放 6346K, 7% free , paused 143ms, tot 下一篇:停止的服务正在做持续的垃圾收集

                相关文章

                    • <bdo id='3HfKg'></bdo><ul id='3HfKg'></ul>

                    <legend id='3HfKg'><style id='3HfKg'><dir id='3HfKg'><q id='3HfKg'></q></dir></style></legend>

                    <tfoot id='3HfKg'></tfoot>
                  1. <small id='3HfKg'></small><noframes id='3HfKg'>

                    <i id='3HfKg'><tr id='3HfKg'><dt id='3HfKg'><q id='3HfKg'><span id='3HfKg'><b id='3HfKg'><form id='3HfKg'><ins id='3HfKg'></ins><ul id='3HfKg'></ul><sub id='3HfKg'></sub></form><legend id='3HfKg'></legend><bdo id='3HfKg'><pre id='3HfKg'><center id='3HfKg'></center></pre></bdo></b><th id='3HfKg'></th></span></q></dt></tr></i><div id='3HfKg'><tfoot id='3HfKg'></tfoot><dl id='3HfKg'><fieldset id='3HfKg'></fieldset></dl></div>