Android SQCipher do I need to close the database?
I've read a lot about using a standard SQLiteDatabase in android and it seems that the best way is to keep one instance of SQLiteOpenHelper and never close the returned SQLiteDatabase object, nor SQLiteOpenHelper. The question is whether those guidelines are valid when using SQCipher encryption library? It seems the close() method of SQLiteOpenHelper in SQCipher package is not empty and do release some stuff. Is it safe to never call this method?
Below is the actual code of 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();
}
}
}
链接地址: http://www.djcxy.com/p/42626.html