Fix memory leak in Launcher
Leak happened when a stack view was on the
workspace and then workspace forced a rebind of
its items (for example, when an app was installed)
Bug # 5629171
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index f9c7bf0..864fca5 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2920,6 +2920,7 @@
final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
layoutParent.removeAllViewsInLayout();
}
+ mWidgetsToAdvance.clear();
if (mHotseat != null) {
mHotseat.resetLayout();
}
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index e2ddf1b..7da55db 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -176,12 +176,16 @@
// Ensure that we don't use the same workspace items data structure on the main thread
// by making a copy of workspace items first.
final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
+ final ArrayList<ItemInfo> appWidgets = new ArrayList<ItemInfo>(sAppWidgets);
mHandler.post(new Runnable() {
@Override
public void run() {
for (ItemInfo item : workspaceItems) {
item.unbind();
}
+ for (ItemInfo item : appWidgets) {
+ item.unbind();
+ }
}
});
@@ -1229,7 +1233,6 @@
}
});
- // Unbind previously bound workspace items to prevent a leak of AppWidgetHostViews.
final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
// Add the items to the workspace.