Out of Memory when allocating cursors

落爺英雄遲暮 提交于 2019-11-30 08:24:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!