From 3f824c0e72ad8cde2dc9b0f4d4d7b621b5535e62 Mon Sep 17 00:00:00 2001 From: Catherine Liu Date: Mon, 11 Jun 2012 16:38:17 -0500 Subject: Fix cursor memory leak In current code, if an application opens a cursor to access a provider, and doesn't close that cursor, later, when this cursor is garbage collected, it won't get closed. This will cause a memory leak in the provider. The leaked memory can only be reclaimed when the application with the leaked cursor was dead. The solution is, close the cursor when it's garbage collected. Change-Id: I786915c46d4672b6b1b37414b3bc1ff8cea2e00b --- core/java/android/database/AbstractCursor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/java/android/database/AbstractCursor.java b/core/java/android/database/AbstractCursor.java index 74fef2993272..754f72e486b4 100644 --- a/core/java/android/database/AbstractCursor.java +++ b/core/java/android/database/AbstractCursor.java @@ -406,6 +406,9 @@ public abstract class AbstractCursor implements CrossProcessCursor { if (mSelfObserver != null && mSelfObserverRegistered == true) { mContentResolver.unregisterContentObserver(mSelfObserver); } + try { + if (!mClosed) close(); + } catch(Exception e) { } } /** -- cgit v1.2.3-59-g8ed1b