imageWithCGImage和内存 [英] imageWithCGImage and memory
问题描述
如果我使用 [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屋!