title: Android: do I need to close Cursor objects?
body: <p>In my database adapter class, I have many methods like this:</p>
  
  <pre><code>public long getContactId(final String phoneNumber) throws SQLException {
      final Cursor cur = mDb.rawQuery(
              "select contact_id from contactphones where number=? limit 1;",
              new String[] { phoneNumber });
      return cur.moveToFirst() ? cur.getLong(0) : -1;
  }
  </code></pre>
  
  <p>I appreciate the brevity of a method like that. But I am not calling Cursor.close(), and I'm not sure if that is a problem or not. Would the Cursor be closed and its resources freed in the Cursor.finalize()? Otherwise I would have to do:</p>
  
  <pre><code>public long getContactId(final String phoneNumber) throws SQLException {
      final Cursor cur = mDb.rawQuery(
              "select contact_id from contactphones where number=? limit 1;",
              new String[] { phoneNumber });
      final boolean retVal = cur.moveToFirst() ? cur.getLong(0) : -1;
      cur.close();
      return retVal;
  }
  </code></pre>