samedi 2 mai 2015

When should I close an SQLite database on Android?

OK, I've been trying to track down all the resources my app leaks. One of the things I've been opening and not closing has been database handles, usually opened through getWritableDatabase() and getReadableDatabase().

Now, its usually easy to close the database after a write, but read operations are usually returning a Cursor. I doubt its legal to close a database handle with an open Cursor. And I certainly don't want to return both a Cursor and the database handle so that I can close them both. Does closing the Cursor automatically close the database handle?

I looked here: http://ift.tt/1e3HL0t

But that seems to close the database handles almost at random, or wherever it seems convenient.

When and where do I close this stuff?

Aucun commentaire:

Enregistrer un commentaire