Fixing minor memory leak with name comparator.

- WidgetsAndShortcutNameComparator was using the actual widget and shortcut resolve
  infos as the key to the label cache.  Neither of these classes override hashCode()
  and we were retrieving a new set of widgets and shortcuts whenever packages changed
  so we would end up creating more and more entries in the cache.  This isn't a huge
  leak, but could lead to problems if Launcher is used for long periods without being
  killed.
- Now, we use a ComponentKey as the key, so that we don't keep a reference to the
  widget/shortcut infos and also ensures that they should hash to the same labels.

Change-Id: I91347ee72363adbc2b075b67dba331e35ab1fe34
This commit is contained in:
Winson Chung
2015-07-27 17:50:13 -07:00
parent a9095e07dd
commit eea0225304
2 changed files with 60 additions and 30 deletions

View File

@@ -39,7 +39,7 @@ public class WidgetsModel {
private ArrayList<Object> mRawList;
private final AppWidgetManagerCompat mAppWidgetMgr;
private final Comparator mWidgetAndShortcutNameComparator;
private final WidgetsAndShortcutNameComparator mWidgetAndShortcutNameComparator;
private final Comparator mAppNameComparator;
private final IconCache mIconCache;
private final AppFilter mAppFilter;
@@ -103,6 +103,7 @@ public class WidgetsModel {
// clear the lists.
mWidgetsList.clear();
mPackageItemInfos.clear();
mWidgetAndShortcutNameComparator.reset();
// add and update.
for (Object o: rawWidgetsShortcuts) {
@@ -139,7 +140,7 @@ public class WidgetsModel {
if (widgetsShortcutsList != null) {
widgetsShortcutsList.add(o);
} else {
widgetsShortcutsList = new ArrayList<Object>();
widgetsShortcutsList = new ArrayList<>();
widgetsShortcutsList.add(o);
pInfo = new PackageItemInfo(packageName);
mIconCache.getTitleAndIconForApp(packageName, userHandle,