使用NSData分配Iphone
我有一种方法,可以从互联网上下载许多图像,然后将它们保存到设备上。代码如下:使用NSData分配Iphone,iphone,ipad,memory,nsdata,Iphone,Ipad,Memory,Nsdata,我有一种方法,可以从互联网上下载许多图像,然后将它们保存到设备上。代码如下: -(IBAction) updateImages { for (x=0; x<[imagesToUpdate count]; x=x+1) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSMutableDictionary *tempDic = [dic objectForKey:[imagesToUpdate
-(IBAction) updateImages {
for (x=0; x<[imagesToUpdate count]; x=x+1) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableDictionary *tempDic = [dic objectForKey:[imagesToUpdate objectAtIndex:x]];
BOOL newDictionary = [self downloadChartForDictionary:tempDic];
[pool drain];
}
}
-(BOOL) downloadChartForDictionary:(NSMutableDictionary *)dictionary {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSMutableDictionary *updatedDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary];
NSString *downloadString = [NSString stringWithFormat:@"http://www.photo.com/%@_0001.jpg",[updatedDictionary objectForKey:@"PDFName"]];
[updatedDictionary setObject:serverAIRAC forKey:@"airac"];
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"MM-dd-y";
NSString *dateString = [formatter stringFromDate:date];
[updatedDictionary setObject:dateString forKey:@"date"];
[formatter release];
NSURL *url = [NSURL URLWithString:downloadString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *savePath = [NSString stringWithFormat:@"%@/%@^%@_%@.jpg",docsPath,serverAIRAC,[updatedDictionary objectForKey:@"airport"],[updatedDictionary objectForKey:@"PDFName"]];
BOOL downloaded = [data writeToFile:savePath atomically:YES];
[pool drain];
return YES;
}
-(iAction)更新图像{
对于(x=0;x您是否尝试了[[[NSData alloc]initWithContentsOfURL:url]自动删除]
?这将把NSData对象放入当前的自动释放池。一个简单的alloc/init创建仍然需要您的显式管理。尝试使用不同的读取选项。我会从开始,因为听起来好像您的数据正在缓存,而您不希望它被缓存。这实际上不是一个问题…For出于某种原因,instruments报告了分配情况,但当我实际运行应用程序时,它从未崩溃。令人沮丧的是,我有另一个控制器,它几乎做同样的事情,而且工作得非常完美。