다음 코드에서 장비가 메모리 누수를 나타냅니다. 나는 모든 곳에서 유지 된 수를 유지하도록 확실히했다. 나는 또한 autorelease 수영장을 추가했습니다, 아직도 메모리 누수가 있습니다. 어떻게 해결할 수 있을까요?SKDatabase 함수에서 메모리 누수를 해결하는 방법은 무엇입니까?
코드 블록 :
- (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;
}
악기 스크린 샷 :
가끔 SQLite가 실수로'free()'해야하는 문자열을 반환합니다. 그것이 문제인지보십시오. – CodaFi
@CodaFi 당신이 맞는 것 같습니다. 이 함수 내에서 변수가 아니라 적절하게 처리해야하는 변수를 반환하십시오. 감사합니다 –
그 남자의 레포에 문제를 던질 수도 있습니다. – CodaFi