You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by zs...@apache.org on 2017/08/01 02:55:02 UTC

[35/50] [abbrv] incubator-weex git commit: * [android] RecyclerView Memory optimization

* [android] RecyclerView Memory optimization


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1a871981
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1a871981
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1a871981

Branch: refs/heads/dev
Commit: 1a871981d0d8af344f4abb8ca1fe927f0d4848c7
Parents: f63bf2c
Author: miomin <69...@qq.com>
Authored: Tue Jul 25 16:51:32 2017 +0800
Committer: miomin <69...@qq.com>
Committed: Tue Jul 25 16:51:32 2017 +0800

----------------------------------------------------------------------
 .../weex/ui/component/list/BasicListComponent.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1a871981/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
index bdec22e..b85ec21 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java
@@ -92,6 +92,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
   private int mListCellCount = 0;
   private boolean mForceLoadmoreNextTime = false;
   private ArrayList<ListBaseViewHolder> recycleViewList = new ArrayList<>();
+  private static int visibleCellCount = 6;
   private static final Pattern transformPattern = Pattern.compile("([a-z]+)\\(([0-9\\.]+),?([0-9\\.]+)?\\)");
 
   private Map<String, AppearanceHelper> mAppearComponents = new HashMap<>();
@@ -818,11 +819,18 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
     if(holder.canRecycled()) {
       recycleViewList.add(holder);
 
+      // recycleViewList allowed max size
+      int threshold = visibleCellCount >= 6 ? (visibleCellCount * 6) : (6*6);
+
       /**
-       * Recycle cache{@link recycleViewList} when recycleViewList.size() > list max child count
+       * Recycle cache{@link recycleViewList} when recycleViewList.size() > list max child count or threshold
        */
-      if (recycleViewList.size() > getChildCount() + 1)
+      if (recycleViewList.size() > getChildCount() + 1 || recycleViewList.size() >= threshold) {
+        WXLogUtils.d(TAG, "Recycle holder list recycled : cache size is " + recycleViewList.size() +
+                ", visibleCellCount is " + visibleCellCount + ", threshold is " + threshold +
+                ", child count is " + getChildCount());
         recycleViewHolderList();
+      }
     } else {
       WXLogUtils.w(TAG, "this holder can not be allowed to  recycled" );
     }
@@ -1188,6 +1196,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
       direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_RIGHT;
     }
 
+    visibleCellCount = lastVisible - firstVisible;
+
     while (it.hasNext()) {
       AppearanceHelper item = it.next();
       WXComponent component = item.getAwareChild();