Shouldn't the database be closed before returning a cursor?


Hey, can you help me understand the code on p556 (listing 34.21)?

[code]public RunCursor queryRun(long id) {
Cursor wrapped = getReadableDatabase().query( … );

return new RunCursor(wrapped);


This code is opening a database through getReadableDatabase(), but there’s no matching database.close() call. In the code that calls this method (listing 34.22) you close the cursor, but nowhere is the database object closed. Obviously it will be cleaned up by the GC sooner or later, however according to several posts on StackOverflow it’s stated that the database must be closed (explicitly). I am currently dealing with Sqlite-related crashes in my app which are difficult to debug and I’m wondering if this could be related.