title: SQLite connection object leaked - Android
body: <p>I am making my first android app, and I took some sqlite tutorials first, that taught me to use a databaseHelper that extends SQLiteOpenHelper. So my databaseHelper does extend SQLiteOpenHelper. I get a sqlite connection leak warning in the Logcat so would like some advice about what to do to fix that. </p>
  
  <p>I get this error: </p>
  
  <pre><code>02-01 21:39:50.740: W/SQLiteConnectionPool(32061): A SQLiteConnection object for database '/data/data/com.btf271.fashionassistant/databases/clothingManager' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
  </code></pre>
  
  <p>My databaseHelper functions that are called where the leak occurs:</p>
  
  <pre><code> public List&lt;Sticker&gt; getObjectsByGenderAndCategory(String gender, String category) {
          List&lt;Sticker&gt; objects = new ArrayList&lt;Object&gt;();
          String selectQuery = String.format(
                  "SELECT * FROM %s WHERE %s = \"%s\" AND %s = \"%s\"",
                  TABLE_OBJECT, KEY_GENDER, gender, KEY_CATEGORY, category);
  
          Log.e(LOG, selectQuery);
  
          SQLiteDatabase db = this.getReadableDatabase();
          Cursor c = db.rawQuery(selectQuery, null);
       try{
          // looping through all rows and adding to list
          if (c.moveToFirst()) {
              do {
                  Object o = createClothingItemJavaObject(c);
  
                  // adding to object list
                  objects.add(o);
              } while (c.moveToNext());
          }
       }finally {
             c.close();
  db.close();
       }
          return objects;
      }
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/a/18148718/3164083">this which I will try tomorrow. It's late</a>. </p>
  
  <p>Thanks. </p>