{"id":3841,"date":"2014-03-30T06:00:47","date_gmt":"2014-03-30T06:00:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/sqlite-android-database-cursor-window-allocation-of-2048-kb-failed-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:00:47","modified_gmt":"2014-03-30T06:00:47","slug":"sqlite-android-database-cursor-window-allocation-of-2048-kb-failed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/sqlite-android-database-cursor-window-allocation-of-2048-kb-failed-collection-of-common-programming-errors\/","title":{"rendered":"SQLite Android Database Cursor window allocation of 2048 kb failed-Collection of common programming errors"},"content":{"rendered":"<p>I have a routine that runs different queries against an SQLite database many times per second. After a while I would get the error<\/p>\n<p><code>\"android.database.CursorWindowAllocationException: - Cursor window allocation of 2048 kb failed. # Open Cursors = \"<\/code> appear in LogCat.<\/p>\n<p>I had the app log memory usage, and indeed when usage reaches a certain limit the I get this error, implying it runs out. My intuition tells me that the database engine is creating a NEW buffer (CursorWindow) every time I run a query, and even though I mark the .close() the cursors, neither the garbage collector nor <code>SQLiteDatabase.releaseMemory()<\/code> are quick enough at freeing memory. I think the solution may lie in &#8220;forcing&#8221; the database to always write into the same buffer, and not create new ones, but I have been unable to find a way to do this. I have tried instantiating my own CursorWindow, and tried setting it to and SQLiteCursor to no avail.<\/p>\n<p>\u00bfAny ideas?<\/p>\n<p>EDIT: re example code request from @GrahamBorland:<\/p>\n<pre><code>public static CursorWindow cursorWindow = new CursorWindow(\"cursorWindow\"); \npublic static SQLiteCursor sqlCursor;\npublic static void getItemsVisibleArea(GeoPoint mapCenter, int latSpan, int lonSpan) {\nquery = \"SELECT * FROM Items\"; \/\/would be more complex in real code\nsqlCursor = (SQLiteCursor)db.rawQuery(query, null);\nsqlCursor.setWindow(cursorWindow);\n}\n<\/code><\/pre>\n<p>Ideally I would like to be able to <code>.setWindow()<\/code> before giving a new query, and have the data put into the same <code>CursorWindow<\/code> everytime I get new data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a routine that runs different queries against an SQLite database many times per second. After a while I would get the error &#8220;android.database.CursorWindowAllocationException: &#8211; Cursor window allocation of 2048 kb failed. # Open Cursors = &#8221; appear in LogCat. I had the app log memory usage, and indeed when usage reaches a certain [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3841","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3841"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3841\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}