Slow widget memory leak.
Bug: 3369806
Framework currently holds a reference to widget factories forever
and doesn't call onDestroy. This causes a large memory leak in
browser since that means bitmaps are held in memory forever. This
explicitly calls onDestroy and tries to free as much memory as possible.
It doesn't fix the problem, just slows the bleeding.
Change-Id: I80832941aa75e30b3b6c951fab2c9cb0a7ed477d
diff --git a/src/com/android/browser/widget/BookmarkThumbnailWidgetService.java b/src/com/android/browser/widget/BookmarkThumbnailWidgetService.java
index 631bf84..cc06349 100644
--- a/src/com/android/browser/widget/BookmarkThumbnailWidgetService.java
+++ b/src/com/android/browser/widget/BookmarkThumbnailWidgetService.java
@@ -109,7 +109,10 @@
int[] ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (ids != null) {
for (int id : ids) {
- mFactories.remove(id);
+ BookmarkFactory bf = mFactories.remove(id);
+ // Workaround a known framework bug
+ // onDestroy is currently never called
+ bf.onDestroy();
}
}
} else if (ACTION_CHANGE_FOLDER.equals(action)) {
@@ -309,9 +312,18 @@
@Override
public void onDestroy() {
- recycleBitmaps();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.unregisterOnSharedPreferenceChangeListener(this);
+
+ // Workaround known framework bug
+ // This class currently leaks, so free as much memory as we can
+ recycleBitmaps();
+ mBookmarks.clear();
+ mBreadcrumbs.clear();
+ if (mLoadTask != null) {
+ mLoadTask.cancel(false);
+ mLoadTask = null;
+ }
}
@Override