我正在按照 Apple Dev 的思路为表实现并发 imageLoader。 NSOpertaion 上的视频。
有趣的是(至少对我而言),在我的 NSOperation 的 main 中,我有这行代码(其中 imageURL 是一个有效的 url 字符串,在 NSOperation 中作为 ivar 存储和保留):
UIImage * newThumbnail = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]];
上面的代码有效,但是仪器在调用 NSData dataWithContentsOfURL 时报告 CFHTTPCookieStorage 泄漏。所以看起来像是 CF 泄漏.. 我对此无能为力。不过,有人说,如果他们切换到 dataWithContentsOfURL:options:error,就不会发生泄漏。
所以我继续尝试,这意味着上面的行变成了:
UIImage * newThumbnail = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL] options:0 error:&error]];
但随后我得到了一个与以前工作的同一个 URLWithString 的异常!:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData initWithContentsOfURL:options:error:]: nil URL argument'
什么给了?
最佳答案
我认为您应该为 Grand Central Dispatch 使用包装器而不是使用 NSOperations。你可以在这里查看我刚才写的一个:https://github.com/MaxKDevelopment/MKImageCenter .
关于ios - NSData dataWithContentsOfURL 泄漏和 datawithContentsOfURL :options:error reports the URL is nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8116094/