Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite Connection leaked although everything closed
    text
    copied!<p>I found many stuff like <code>close the connection</code> and <code>close the cursor</code>, but I do all this stuff. Still the SQLite connection leaks and I get a warning like this:</p> <pre><code>A SQLiteConnection object for database was leaked! </code></pre> <p>I have a database manager this, which I call in my activities with the following code:</p> <pre><code>DatabaseManager dbm = new DatabaseManager(this); </code></pre> <p>The code of my database manager class follows now:</p> <pre><code>public class DatabaseManager { private static final int DATABASE_VERSION = 9; private static final String DATABASE_NAME = "MyApp"; private Context context = null; private DatabaseHelper dbHelper = null; private SQLiteDatabase db = null; public static class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { //create database tables } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //destroy and recreate them } } public DatabaseManager(Context ctx) { this.context = ctx; } private DatabaseManager open() throws SQLException { dbHelper = new DatabaseHelper(context); db = dbHelper.getWritableDatabase(); if (!db.isReadOnly()) { db.execSQL("PRAGMA foreign_keys = ON;"); } return this; } private void close() { dbHelper.close(); } } </code></pre> <p>When I call a database method, I do the following thing:</p> <pre><code>public Object getData() { open(); //... database operations take place ... close(); return data; } </code></pre> <p>But as I said, I still get this SQLite connection leaked warning. </p> <p>What am I doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload