From ba223760895e62ad2fcb85476984cb29018860c9 Mon Sep 17 00:00:00 2001 From: Bjorn Bringert Date: Wed, 26 Aug 2009 13:18:40 +0100 Subject: [PATCH] Close suggestion cursors that arrive after adapter is closed Before, after using the Browser, memory-hungry apps could become very sluggish. This was because the search dialog in the system process had the BrowserProvider open, which in turn had EnhancedGoogleSearch open. Since EhancedGoogleSearch runs in acore, the system would keep both the Browser process and acore to stay around forever. The cause (or at least one common cause) for this was that if the user types quickly, and clicks on a suggestion before the displayed suggestions have caught up, some suggestion cursors are not be closed. This change solves this problem by adding a close() method to SuggestionsAdapter. SuggestionsAdapter now closes any cursors that are passed to it after close() is called. Fixes http://b/issue?id=2078226 "global search holding reference to browser: system -> browser -> acore = :(" --- core/java/android/app/SearchDialog.java | 2 +- core/java/android/app/SuggestionsAdapter.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java index b75bec2dc8eb4..5844079e616cb 100644 --- a/core/java/android/app/SearchDialog.java +++ b/core/java/android/app/SearchDialog.java @@ -428,7 +428,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS mSearchAutoComplete.setAdapter((SuggestionsAdapter)null); // close any leftover cursor if (mSuggestionsAdapter != null) { - mSuggestionsAdapter.changeCursor(null); + mSuggestionsAdapter.close(); } mSuggestionsAdapter = null; } diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java index 52e4a1f255a2f..90f8c503607b3 100644 --- a/core/java/android/app/SuggestionsAdapter.java +++ b/core/java/android/app/SuggestionsAdapter.java @@ -65,6 +65,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter { private WeakHashMap mOutsideDrawablesCache; private SparseArray mBackgroundsCache; private boolean mGlobalSearchMode; + private boolean mClosed = false; // Cached column indexes, updated when the cursor changes. private int mFormatCol; @@ -199,6 +200,12 @@ class SuggestionsAdapter extends ResourceCursorAdapter { } } + public void close() { + if (DBG) Log.d(LOG_TAG, "close()"); + changeCursor(null); + mClosed = true; + } + /** * Cache columns. */ @@ -206,6 +213,12 @@ class SuggestionsAdapter extends ResourceCursorAdapter { public void changeCursor(Cursor c) { if (DBG) Log.d(LOG_TAG, "changeCursor(" + c + ")"); + if (mClosed) { + Log.w(LOG_TAG, "Tried to change cursor after adapter was closed."); + if (c != null) c.close(); + return; + } + try { Cursor oldCursor = getCursor(); super.changeCursor(c);