Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My application give me this warning

A SQLiteConnection object for database '+data+data+com_example_test+database' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

But I close the db object and the cursor after every use.

        try {
            while (cursor.moveToNext()) {
              ...
            }
        } finally {
            if (cursor != null && !cursor.isClosed())
                cursor.close();
        }

...
    db.close();

Can you help me for understand what is the problem? thanks!!!

UPDATE! I try this solution from this post SQLite Connection leaked although everything closed

and I don't have memory leak anymore, is it a good solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

Possible Solutions:

  • You have not committed the transactions you have started (You should always close the transaction once you started)
  • Check whether you have closed the cursors you have opened if you are using Sqlite (Looks like you have done this step from the code you posted)
  • Also move the db.close to finally block
  • You have not called db.close on a database before deleting it with context.deleteDatabase(...) and then recreating it with dbHelper.getWritableDatabase()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...