Android SQCipher do I need to close the database?

I read a lot about using standard SQLiteDatabase in android, and it seems like the best way is to save one instance of SQLiteOpenHelper and never close the returned SQLiteDatabase or SQLiteOpenHelper object. The question is, are these recommendations valid when using the SQCipher encryption library? It seems that the SQLiteOpenHelper close () method in the SQCipher package is not empty and frees up some things. Is it safe to never call this method?

The following is the actual code of the SQLiteDatabase.close () method from Github ( http://goo.gl/u4L0C ):

public void close() { if (!isOpen()) { return; // already closed } lock(); try { closeClosable(); // close this database instance - regardless of its reference count value onAllReferencesReleased(); } finally { unlock(); } } private void closeClosable() { /* deallocate all compiled sql statement objects from mCompiledQueries cache. * this should be done before de-referencing all {@link SQLiteClosable} objects * from this database object because calling * {@link SQLiteClosable#onAllReferencesReleasedFromContainer()} could cause the database * to be closed. sqlite doesn't let a database close if there are * any unfinalized statements - such as the compiled-sql objects in mCompiledQueries. */ deallocCachedSqlStatements(); Iterator<Map.Entry<SQLiteClosable, Object>> iter = mPrograms.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<SQLiteClosable, Object> entry = iter.next(); SQLiteClosable program = entry.getKey(); if (program != null) { program.onAllReferencesReleasedFromContainer(); } } } 
+4
source share

All Articles