Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

* [android] fix : list OOM cause by viewHolder cache,set the upper limit for the viewHolder cache pool #512

Merged
merged 2 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ public void preCalculateCellWidth(){
} else if (Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO == mColumnCount) {
mColumnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
mColumnCount = mColumnCount > 0 ? mColumnCount :1;
if (mColumnCount <= 0)
mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
mColumnWidth =((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
} else if(Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO != mColumnCount){
int columnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
mColumnCount = columnCount > mColumnCount ? mColumnCount :columnCount;
if (mColumnCount <= 0)
mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
mColumnWidth= ((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
}
mIsPreCalculateCellWidth = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,9 @@ protected T initComponentHostView(@NonNull Context context) {
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);

if (newState == RecyclerView.SCROLL_STATE_IDLE) {
for (ListBaseViewHolder holder : recycleViewList) {
if (holder != null
&& holder.getComponent() != null
&& !holder.getComponent().isUsing()) {
holder.recycled();
}
}
recycleViewList.clear();
}
if (newState == RecyclerView.SCROLL_STATE_IDLE)
recycleViewHolderList();

List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
Expand Down Expand Up @@ -382,6 +375,17 @@ public void onGlobalLayout() {
return bounceRecyclerView;
}

private void recycleViewHolderList() {
for (ListBaseViewHolder holder : recycleViewList) {
if (holder != null
&& holder.getComponent() != null
&& !holder.getComponent().isUsing()) {
holder.recycled();
}
}
recycleViewList.clear();
}

@Override
public void bindStickStyle(WXComponent component) {
stickyHelper.bindStickStyle(component, mStickyMap);
Expand Down Expand Up @@ -833,6 +837,12 @@ public void onViewRecycled(ListBaseViewHolder holder) {
holder.setComponentUsing(false);
if(holder.canRecycled()) {
recycleViewList.add(holder);

/**
* Recycle cache{@link recycleViewList} when recycleViewList.size() > list max child count
*/
if (recycleViewList.size() > getChildCount() + 1)
recycleViewHolderList();
} else {
WXLogUtils.w(TAG, "this holder can not be allowed to recycled" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public void addChild(WXComponent child, int index) {
return;
}
setRefreshOrLoading(child);

// Synchronize DomObject's attr to Component and Native View
if(mDomObject.getColumnWidth() != mColumnWidth ||
mDomObject.getColumnCount() != mColumnCount ||
mDomObject.getColumnGap() != mColumnGap) {
updateRecyclerAttr();
getHostView().getInnerView().initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation());
}
}


Expand Down