전문가 님, NSThread에 약간의 문제가 있습니다. Xcode는 "* __NSAutoreleaseNoPool() : 클래스 NSCFString의 객체 0x5694dc0이 풀없이 자동으로"그냥 누출 된 "오류를 자동 응답합니다.Xcode Objective C - NSThread를 사용하여 NSAutoreleaseNoPool 오류가 발생했습니다.
정확히 내가 줄을 가진 풀을 선언하고 있습니다. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
내 루프가 끝날 때 사용 : [풀 릴리스];
왜냐하면 performSelectorInBackground로 위임 메서드를 사용하고 있기 때문입니까? 고마워요 stackoverflow.
- (void)preFetch { //process filenames to be downloaded and assign types to each one
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *regions = [NSArray arrayWithObjects: @"dr_national", @"ds_ir", @"conus_FL360", @"FL360_conus", @"dr_nw", @"dr_nc", @"dr_ne", @"dr_sw", @"dr_sc", @"dr_se", @"ds_ir_nw", @"ds_ir_nc", @"ds_ir_ne", @"ds_ir_sw", @"ds_ir_sc", @"ds_ir_se", nil];
NSError* error;
for (NSString *regionDir in regions) {
NSLog(@"region now: %@", regionDir); foo = 0;
NSString *regUrl = [NSString stringWithFormat:@"http://someUrl/%@/index.lst", regionDir ];
NSString* text1 = [NSString stringWithContentsOfURL:[NSURL URLWithString:regUrl ] encoding:NSASCIIStringEncoding error:&error];
NSArray *listItems = [text1 componentsSeparatedByString:@"\n"];
for (int k=0; k<[listItems count]; k++) {
if ([[listItems objectAtIndex:k] length] != 0){
NSString *newpath = [NSString stringWithFormat:@"http://someUrl/%@", [listItems objectAtIndex:k]];
NSLog(@"newpath: %@",newpath);
[self performSelectorInBackground:@selector(moveProgressBar) withObject:nil];
[self fetchImages:newpath:type]; //pass multiple arguments to fetchImages, newpath and type
}
}
}
[pool release];
}
- (void)moveProgressBar{
[delegate increaseAmount];
}
그건 속임수 였어! 고마워, 잠시 동안 이것에 난처한되었습니다. –
delegate 메소드의 increaseAmount는 주 스레드에게 진행률 표시 막대를 늘리라고 알려주며 긴로드가 올바른 주 스레드입니다. 진행보기 업데이트는 스폰 된 스레드입니다. –
백그라운드 스레드에서 메서드를 호출하면 주 스레드에서 메서드가 호출됩니다. 조금 복잡하게 보입니다. 그래도 문제가 해결되어서 다행입니다. – paulbailey