仪器在以下代码中显示内存泄漏。我确保在任何地方都保持保留计数。我还添加了自动释放池,仍然存在内存泄漏。如何解决这个问题?
代码块:
- (NSArray *)lookupAllForSQL:(NSString *)sql
{
sqlite3_stmt *statement;
id result = nil;
NSMutableArray *thisArray = [NSMutableArray arrayWithCapacity:4];
statement = [self prepare:sql];
if (statement)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *thisDict = [NSMutableDictionary dictionaryWithCapacity:4];
for (int i = 0 ; i < sqlite3_column_count(statement) ; i++)
{
NSAutoreleasePool *poolInside = [[NSAutoreleasePool alloc] init];
if(sqlite3_column_type(statement,i) == SQLITE_NULL)
{
continue;
}
if (sqlite3_column_decltype(statement,i) != NULL &&
strcasecmp(sqlite3_column_decltype(statement,i),"Boolean") == 0)
{
result = [NSNumber numberWithBool:(BOOL)sqlite3_column_int(statement,i)];
}
else if (sqlite3_column_type(statement,i) == SQLITE_INTEGER)
{
result = [NSNumber numberWithInt:(int)sqlite3_column_int(statement,i)];
}
else if (sqlite3_column_type(statement,i) == SQLITE_FLOAT)
{
result = [NSNumber numberWithFloat:(float)sqlite3_column_double(statement,i)];
}
else
{
if((char *)sqlite3_column_text(statement,i) != NULL)
{
//result = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)];
[thisDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,i)]
forKey:[NSString stringWithUTF8String:sqlite3_column_name(statement,i)]];
//[result release];
result = nil;
}
}
if (result)
{
[thisDict setObject:result forKey:[NSString stringWithUTF8String:sqlite3_column_name(statement,i)]];
}
[poolInside drain];
}
[thisArray addObject:[NSDictionary dictionaryWithDictionary:thisDict]];
[pool drain];
}
}
sqlite3_finalize(statement);
return thisArray;
}
仪器截图: