imageWithCGImage和内存 [英] imageWithCGImage and memory

查看:104
本文介绍了imageWithCGImage和内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 [UIImage imageWithCGImage:] ,传入 CGImageRef ,然后释放 CGImageRef 或者UIImage在解除分配时是否会自行处理?

If I use [UIImage imageWithCGImage:], passing in a CGImageRef, do I then release the CGImageRef or does UIImage take care of this itself when it is deallocated?

文档不完全清楚。

最初我在CGImageRef中调用了 CGImageRelease 它到 imageWithCGImage:,但是导致在模拟器中发出 malloc_error_break 警告声称发生双重自由。 p>

Originally I called CGImageRelease on the CGImageRef after passing it to imageWithCGImage:, but that caused a malloc_error_break warning in the Simulator claiming a double-free was occurring.

推荐答案

我同意你的看法 - 这篇文档最适合这个API。根据你的经验,我会得出结论,你对这两个对象的生命负责 - UIImage CGImageRef 。除此之外,你必须确保 CGImageRef 的生命周期至少与 UIImage 一样长明显的原因)。

I agree with you -- the documentation is muddled at best for this API. Based on your experiences, then, I would conclude that you are responsible for the lifetime of both objects - the UIImage and the CGImageRef. On top of that you have to make sure the lifetime of the CGImageRef is at least as long as the UIImage (for obvious reasons).

这篇关于imageWithCGImage和内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆