빡빡한 루프에서 NSAutoreleasePool을 사용하고 있지만 아래의 메서드에서 다음 경고 행을 통해 메모리 경고가 발생하고 궁극적으로 내 앱이 충돌합니다. 가버 리다). 누구나 이것이 왜 그런지 생각할 수 있습니까?신비한 메모리 누수 - NSString 자동 해제 문제
filepath = [docpath stringByAppendingPathComponent:file];
-(void)fileCleanup
{
NSString *documentspath = [AppSession documentsDirectory];
NSString *docpath = [documentspath stringByAppendingPathComponent:@"docs"];
NSFileManager *filemanager = [NSFileManager defaultManager];
NSArray *files = [filemanager subpathsOfDirectoryAtPath:docpath error:NULL];
NSLog(@"fileCleanup");
if(files != nil && [files count] > 0)
{
BOOL deletefile;
NSString *filepath;
NSAutoreleasePool *readPool;
NSString *testfile;
NSString *file;
for(file in files)
{
deletefile = YES;
for (testfile in allFiles) {
readPool = [[NSAutoreleasePool alloc] init];
//line below is causing memory leak!
filepath = [docpath stringByAppendingPathComponent:file];
//if([filepath isEqualToString:testfile])
//{
// deletefile = NO;
// break;
//}
[readPool drain];
}
if(deletefile)
{
[self logText:[@"\nD: " stringByAppendingString:[@"docs/" stringByAppendingPathComponent:file]]];
[filemanager removeItemAtPath:[docpath stringByAppendingPathComponent:file] error:NULL];
}
}
}
메모리가 부족할 수 있으므로 언급 한 행이 최고 수위에 도달하는 남은 몇 바이트를 할당 할 수 있습니다. 바깥 쪽 루프에서는 메인 루프가 현재 이벤트 처리를 마칠 때까지 해제되지 않는 많은 로깅 문자열을 만듭니다. autorelease 풀은 도움이되지 않습니다. – Codo