What could be causing this SQLite CursorWindowAllocationException? What could be causing this SQLite CursorWindowAllocationException? sqlite sqlite

What could be causing this SQLite CursorWindowAllocationException?


That is an OutOfMemoryError, in effect. Quoting the comments for that exception class:

This exception is thrown when a CursorWindow couldn't be allocated, most probably due to memory not being available.

The error message shows that you have 530 open Cursor objects, which may be part of your problem. For example, you are leaking a Cursor in your getCourse() method. Make sure that you close your Cursor as soon as you are done with it.

If that does not help, you will need to treat this like an OutOfMemoryError and determine where else you are wasting heap space, perhaps by using tools like MAT.


Cursors need to be closed:

Cursor c = db.query(...);try {    ...} finally {    c.close();}


If you do not want to mess with multiple local variables to return, you can return the Cursor object and then close it from the calling method.

This is in response to " Hmm. Sometimes I use return cursor.getString(0). I guess I can't close the cursor after a return, nor return using it after a close. I'll have to return temp variables, right? – NSouth Oct 4 '14 at 20:44: &

@NSouth: "I'll have to return temp variables, right?" -- if you mean local variables (stuff declared in the method body), then yes. – CommonsWare Oct 4 '14 at 20:46

I know this is more of a comment then a answer, but I do not have the reputation points to comment and thought this might be helpful.