Skip to content

Commit 3f824c0

Browse files
author
Catherine Liu
committed
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
1 parent 7d77977 commit 3f824c0

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

core/java/android/database/AbstractCursor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ protected void finalize() {
406406
if (mSelfObserver != null && mSelfObserverRegistered == true) {
407407
mContentResolver.unregisterContentObserver(mSelfObserver);
408408
}
409+
try {
410+
if (!mClosed) close();
411+
} catch(Exception e) { }
409412
}
410413

411414
/**

0 commit comments

Comments
 (0)