A SQLiteConnection object for database was leaked! Please fix your application

前端 未结 5 659
一整个雨季
一整个雨季 2020-12-15 02:37

My application give me this warning

A SQLiteConnection object for database \'+data+data+com_example_test+database\' was leaked! Please fix your ap

相关标签:
5条回答
  • 2020-12-15 03:15

    Probably you forgot to remove the break point of debugging sample:

    0 讨论(0)
  • 2020-12-15 03:20

    In my case the error was caused when y try to download new data and database should be updated.

    I solved it instantiating the database by calling a SELECT 0. That cause database to be updated, so after that I try to download the new data. And worked fine.

    0 讨论(0)
  • 2020-12-15 03:24

    Just drag that db.close up into the finally block.

    0 讨论(0)
  • 2020-12-15 03:27

    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()
    0 讨论(0)
  • 2020-12-15 03:30
    //Inside your SQLite helper class
    @Override
    public synchronized void close () {
        if (db != null) {
            db.close();
            super.close();
        }
    }
    
    //Inside the activity that makes a connection to the helper class
    @Override
    protected void onDestroy () {
        super.onDestroy();
        //call close() of the helper class
        dbHelper.close();
    }
    
    0 讨论(0)
提交回复
热议问题