JuL
JuL

Reputation: 113

Should I have to close used cursor by ContentResolver?

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

Answers (1)

Suragch
Suragch

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

Related Questions