Android SQCipher是否需要关闭数据库?

我已经阅读了很多关于在an​​droid中使用标准SQLiteDatabase的知识,似乎最好的方法是保留SQLiteOpenHelper的一个实例,并且永远不要关闭返回的SQLiteDatabase对象,也不要关闭SQLiteOpenHelper。 问题是在使用SQCipher加密库时这些准则是否有效? 看起来SQCipher包中的SQLiteOpenHelper的close()方法不是空的,而是发布一些东西。 永远不要调用这种方法是否安全?

以下是Github的SQLiteDatabase.close()方法的实际代码(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/42625.html

上一篇: Android SQCipher do I need to close the database?

下一篇: onMeasure custom view explanation