下面是代码。它下载缩略图,然后尝试基于缩略图文件路径创建图像。但它在方法调用"imageWithContentsOfFile"时给了我EXC_BAD_ACCESS错误。虽然EXC_BAD_ACCESS处理了试图访问已发布对象的代码,但我很可能不知道它可能是哪个对象。如果有任何帮助,我们将不胜感激!
NSBlockOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
if([[NSFileManager defaultManager] fileExistsAtPath:operation.destinationPath ]){
NSString *key = [[MEURLCacheKeyRegister sharedRegister] cacheKeyForURL:operation.fileUrl];
UIImage *image = [UIImage imageWithContentsOfFile:operation.destinationPath];
}else{
DDLogDebug(@"Thumbnail file doesn't exist at %@", operation.destinationPath);
}
}
}];
AFDownloadRequestOperation *requestOperation = [FileServerDownloadUtils downloadOperationForURL:operation.fileUrl
destinationPath:operation.destinationPath
completion:completionOperation];
[self.fileSyncQueue addOperation:requestOperation];
EXC_BAD_ACCESS
表示对象在被访问时已被释放。
如果我是你,我会尝试以下事情:
- 使用
.jpg
而不是.jpg.prv.jpg
扩展名保存文件 - 尝试使用
initWithContentsOfFile
而不是imageWithContentsOfFile
作为imageWithContentsOfFile
自动释放图像,这在极少数边缘情况下会造成这样的崩溃 - 将代码传递给
block
时,通过对self
进行弱引用来访问对象属性。类似这样的东西:__weak MyController *weakSelf = self
。然后使用weakSelf
访问块内的属性
这些只是一些线索,可以帮助你进一步挖掘。您可以使用NSZombie
和其他分析工具来确定它。