在 IOS 上向联系人添加图像时出现令人费解的内存泄漏
我目前在仪器中的这条线上有泄漏,每次调用时我都会泄漏几百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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不必担心那个物体。由于
UIImagePNGRepresentation
将返回一个autoreleased
对象,因此不会出现任何内存泄漏。由于dataRef
是一个autoreleased
对象,因此您不应手动释放它。I think you need not to worry about that object. Since
UIImagePNGRepresentation
will return you anautoreleased
object, so there won't be any memory leak. SincedataRef
is anautoreleased
object you should not release it manually.