Reputation: 113
For example, given the following code:
Cursor myCursor = context.getContentResolver()
.query(MediaStore.CONTENT_URI, null, null, null, null);`
Do I have to close "myCursor"?
Thanks.
Upvotes: 3
Views: 2451
Reputation: 511866
Cursors should always be closed in some way to avoid memory leaks. However, if you are implementing LoaderManager.LoaderCallbacks<Cursor>
then overriding the following method closes the cursor for you.
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
cursorAdapter.swapCursor(null);
}
Upvotes: 2