ios - NSData dataWithContentsOfURL 泄漏和 datawithContentsOfURL :options:error reports the URL is nil?

标签 ios memory-leaks nsdata nsurl core-foundation

我正在按照 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/

相关文章:

iphone - ios UITableView删除/重新排列编辑模式但不显示删除图标

ios - 在 Objective-C 中读取 gzip 压缩字符串失败?

ios - 按下主页按钮时暂停 Sprite Kit 场景

c++ - valgrind 报告 getpwuid() 在 Ubuntu 中的 c++ 泄漏

node.js - 在 Node.js 中使用流时内存泄漏?

java - 了解 Android 应用程序中的内存泄漏

ios - 来自 NSData 的 UIImage 在 iPad2 上工作正常但在 iPad1 上不工作

objective-c - 从 AVAssetWriter 读取实时 H.264 输出时数据损坏

iOS 9 Facebook 登录模拟器-canOpenURL : failed for URL: "fbauth2:///" - error: "(null)"

ios - 使用三个 View 的无限循环对 UIScrollView 进行分页