title: android: do we need to close Db after closing the cursor
body: <p>From source code of SQLiteCursor (stack trace):</p>
  
  <pre><code>at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
  at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:325)
  at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45)
  at android.database.sqlite.SQLiteProgram.onAllReferencesReleased(SQLiteProgram.java:119)
  at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45)
  at android.database.sqlite.SQLiteProgram.close(SQLiteProgram.java:296)
  at android.database.sqlite.SQLiteQuery.close(SQLiteQuery.java:136)
  at android.database.sqlite.SQLiteCursor.close(SQLiteCursor.java:506)
  </code></pre>
  
  <p>Does it mean that, closing the last cursor will also close the Database. And we dont need to close it explicitly, as in this code:</p>
  
  <pre><code>    SQLiteDatabase rdb = db.getReadableDatabase();
      Cursor resultCursor = null;
      String patternQuery = SQLiteQueryBuilder.buildQueryString(true, "Store", columns, where, null, null, null, null);
  
      try
      {
          resultCursor = rdb.rawQuery(patternQuery, null);
  
  
          resultCursor.moveToFirst();
          if (resultCursor.getCount() &gt; 0)
          {
              while (!resultCursor.isAfterLast())
              {
                  result.add(resultCursor.getString(0));
                  resultCursor.moveToNext();
              }
          }
      }
      catch (Exception e)
      {
          Log.d("DB", "Caught an exception while getting pattern based results: " + e);
      }
      finally
      {
          if (resultCursor != null)
          {
              resultCursor.close();
          }
          if (rdb.isOpen())
          {
              rdb.close();
          }
      }
  </code></pre>
  
  <p>so here, we dont need to close the rdb?</p>
  
  <p>note: the cursor object keeps the reference to the database, so it gets a lock on same on each query. Therefore 'SQLiteDatabse.dbclose' effectively closes same database. </p>