这是我的代码,它不释放内存 它达到60 mb并且应用程序杀死
for(int i = 0; i< [modelList count]; i ++){
url=@"http://192.168.0.101/images/projectimages/";
url=[url stringByAppendingString:[modelList objectAtIndex:i]];
url=[url stringByAppendingString:@".jpg"];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSData *imageData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
destinationPath=[documentsDirectory stringByAppendingString:@"/modelimages"];
destinationPath=[destinationPath stringByAppendingPathComponent:[modelList objectAtIndex:i]];
destinationPath=[destinationPath stringByAppendingString:@".jpg"];
[imageData writeToFile:destinationPath atomically:YES];
[imageData release];
//imageData=nil;
//[myurl release];
//[imageData release];
value=value+divideValue;
printf("%f\n",value);
[NSThread detachNewThreadSelector:@selector(updateProgressBar)toTarget:self withObject:nil];
}
答案 0 :(得分:2)
这太可怕了:
[NSThread detachNewThreadSelector:@selector(updateProgressBar)toTarget:self withObject:nil];
因为它:
我认为做更好的事情会更好:
[self performSelectorOnMainThread:@selector(updateProgressBar)
withObject:nil // or any object you need to pass
waitUntilDone:NO] //
以你给出的方法为例 - 它应该在一个单独的线程中运行。 在这种情况下,您将有一个后台线程完成所有艰苦工作,它将通知主线程有关用户界面更新。