android - Do I have to close the Cursor object whenever I call rawQuery()? -


i'm planning use android sqlite first time.

cursor c = db.rawquery("some select command here", null);  // jobs cursor..  c = db.rawquery("another select command here", null);  // jobs cursor..  c.close(); db.close();  c = null; db = null; 

as can see, i'm trying call rawquery() method several times.

  1. do have close cursor before call rawquery() method again?

  2. do have assign null variables after closing cursor , database above?

do have close cursor before call rawquery() method again?

close cursor whenever finished reading it. release resources opened cursor, yes, should close first cursor before second query.

do have assign null variables after closing cursor , database above?

it depends on scope of variables. if code looks this...

class foo {     void dosomething() {         sqlitedatabase db = ...         cursor c = db.rawquery...         // other stuff         c.close();         db.close();     } } 

... there's no point nulling them out because go out of scope when method finishes execution. actual code might different. if have reason wanting allow objects garbage collected, can null out variables.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -