嘿专家,我在使用 NSThread 时遇到了一些麻烦。Xcode 不断给我“ * __NSAutoreleaseNoPool(): NSCFString 类的对象 0x5694dc0 自动释放,没有适当的池 - 只是泄漏”错误。
我使用 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 行正确地声明了池。
然后在我的循环结束时,我使用:[pool release];
是因为我使用委托方法作为 performSelectorInBackground 吗?感谢堆栈溢出。
- (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];
}