我让我的 sqlite 执行查询代码如下。Instruments 在 NSDictionary 分配和释放行(在 while 循环内)中捕获了内存泄漏。有人能指出那些 alloc/release 有什么问题吗?
- (NSMutableArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args {
sqlite3_stmt *sqlStmt;
if (![self prepareSql:sql inStatament:(&sqlStmt)])
return nil;
int i = 0;
int queryParamCount = sqlite3_bind_parameter_count(sqlStmt);
while (i++ < queryParamCount)
[self bindObject:[args objectAtIndex:(i - 1)] toColumn:i inStatament:sqlStmt];
NSMutableArray *arrayList = [[NSMutableArray alloc]init]; // instrument marks leak 0.1 % on this line
NSUInteger rcnt= arrayList.retainCount;
int columnCount = sqlite3_column_count(sqlStmt);
while ([self hasData:sqlStmt]) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; // instrument marks leak 13% on this line
for (i = 0; i < columnCount; ++i) {
id columnName = [self columnName:sqlStmt columnIndex:i];
id columnData = [self columnData:sqlStmt columnIndex:i];
[dictionary setObject:columnData forKey:columnName];
}
[arrayList addObject:dictionary];
[dictionary release];// instrument marks leak 86.9 % on this line
}
sqlite3_finalize(sqlStmt);
rcnt=arrayList.retainCount;
return arrayList ;
}
非常感谢任何帮助/指针。这几天一直在为此苦苦挣扎。