Out of Memory when allocating cursors Out of Memory when allocating cursors sqlite sqlite

Out of Memory when allocating cursors


The call to cursor.close() should be in a finally block in case an exception is thrown while you're iterating over it.

Cursor cursor = mDatabase.query("nodes", null,         "level = " + wrapSql(String.valueOf(level.getId())), null, null, null, null);try {    while (cursor.moveToNext()) {        l.add(parseNodeFromCursor(cursor));    }} finally {    cursor.close();}


One of the reasons for occurring Out of Memory error is you are not closing your cursor.

As I can see, you are calling cursor.close(), but is it the right place where you should call this method or check if you should close it on some other place.

EDIT:

If your activity is managing your Cursor, you may consider stop managing it and closing everything in the onPause method, and in onResume open everything up and fillData once again.