From 0cad1116add5303d7c06cc21182527cebc42aff6 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Wed, 16 Nov 2011 20:43:29 -0800 Subject: [PATCH] Reduce peak memory use in PagedView --- src/com/android/launcher2/PagedView.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 3f5652e1d8..f4ba63cd67 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -1591,22 +1591,29 @@ public abstract class PagedView extends ViewGroup { int upperPageBound = getAssociatedUpperPageBound(page); if (DEBUG) Log.d(TAG, "loadAssociatedPages: " + lowerPageBound + "/" + upperPageBound); + // First, clear any pages that should no longer be loaded + for (int i = 0; i < count; ++i) { + Page layout = (Page) getPageAt(i); + if ((immediateAndOnly && i != page) || + (i < lowerPageBound) || + (i > upperPageBound)) { + if (layout.getPageChildCount() > 0) { + layout.removeAllViewsOnPage(); + } + mDirtyPageContent.set(i, true); + } + } + // Next, load any new pages for (int i = 0; i < count; ++i) { if ((i != page) && immediateAndOnly) { continue; } Page layout = (Page) getPageAt(i); - final int childCount = layout.getPageChildCount(); if (lowerPageBound <= i && i <= upperPageBound) { if (mDirtyPageContent.get(i)) { syncPageItems(i, (i == page) && immediateAndOnly); mDirtyPageContent.set(i, false); } - } else { - if (childCount > 0) { - layout.removeAllViewsOnPage(); - } - mDirtyPageContent.set(i, true); } } }