解决方法:
方法一:
- (BOOL)_dbClose {
...
// 原代码
// if (_dbStmtCache) CFRelease(_dbStmtCache);
// 替换为
if (_dbStmtCache) {
CFIndex size = CFDictionaryGetCount(_dbStmtCache);
CFTypeRef *valuesRef = (CFTypeRef *)malloc(size * sizeof(CFTypeRef));
CFDictionaryGetKeysAndValues(_dbStmtCache, NULL, (const void **)valuesRef);
const sqlite3_stmt **stmts = (const sqlite3_stmt **)valuesRef;
for (CFIndex i = 0; i < size; i ++) {
sqlite3_stmt *stmt = stmts[i];
sqlite3_finalize(stmt);
}
free(valuesRef);
CFRelease(_dbStmtCache);
}
...
}
方法二:
static void _finalizeStatement(const void *key, const void *value, void *context) {
sqlite3_finalize((sqlite3_stmt *)value);
}
- (BOOL)_dbClose {
...
// 原代码
// if (_dbStmtCache) CFRelease(_dbStmtCache);
// 替换为
if (_dbStmtCache) {
CFDictionaryApplyFunction(_dbStmtCache, _finalizeStatement, NULL);
CFRelease(_dbStmtCache);
}
...
}