在 IOS 上向联系人添加图像时出现令人费解的内存泄漏

发布于 2024-10-18 00:53:50 字数 594 浏览 2 评论 0原文

我目前在仪器中的这条线上有泄漏,每次调用时我都会泄漏几百K-

NSData *dataRef = UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]);
ABPersonSetImageData(newRecord, (CFDataRef)dataRef, nil);

当我删除上面的线时,我很好。

整个程序中只提到了dataRef。我尝试 CFrelease-ing 它作为测试,但这会由于引用已释放的对象而导致崩溃。

我尝试将所有内容连接到一行中,

ABPersonSetImageData(newRecord,(CFDataRef) UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]), nil);

但得到了相同的结果。

我第一次预计会发生泄漏,因为众所周知,Imagenamed 会缓存图像对象,而且在 iOS4 之前,该调用被报告发生泄漏,但我不认为会持续泄漏。

有什么想法吗?相关问题之前已经在这里提出过几次,但似乎没有人给出答案。

I currently have a leak on this line in instruments, I leak a few hundred K each time this is called-

NSData *dataRef = UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]);
ABPersonSetImageData(newRecord, (CFDataRef)dataRef, nil);

When I rem out the above lines, I'm good.

dataRef is only mentioned here in the entire program. I tried CFrelease-ing it as a test, but that causes a crash due to referencing a deallocated object.

i tried concatenating it all into one line,

ABPersonSetImageData(newRecord,(CFDataRef) UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]), nil);

but I got the same results.

I would half-expect a leak the first time, as Imagenamed is well known to cache the image object, and the call was reported to leak pre-iOS4, but I wouldn't expect ongoing leaks.

Any ideas? related questions have been raised here before a few times but no-one seemed to have an answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我认为你不必担心那个物体。由于 UIImagePNGRepresentation 将返回一个 autoreleased 对象,因此不会出现任何内存泄漏。由于 dataRef 是一个 autoreleased 对象,因此您不应手动释放它。

I think you need not to worry about that object. Since UIImagePNGRepresentation will return you an autoreleased object, so there won't be any memory leak. Since dataRef is an autoreleased object you should not release it manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文