[UIImageAsset retain]:发送给deallocated实例的消息 [英] [UIImageAsset retain]: message sent to deallocated instance
问题描述
一行
UIImage *tempImage = [UIImage imageNamed:@"gradient-image"];
在后台线程的NSOperation中执行。
代码在这里打破消息:
gets executed inside an NSOperation, on the background thread. The code breaks here with the message:
[UIImageAsset retain]: message sent to deallocated instance
我的图像名称为 gradient-image
in Images.xcassets
。
老实说,我甚至不知道其他相关信息是什么。
I have the image by the name gradient-image
in Images.xcassets
.
Honestly, I don't even know what other info would be relevant.
这种情况很少发生,我无法一致地重现它。
我用谷歌搜索了一下,但结果并不多。所以,我决定在这里创建一个问题。
This happens on rare occasions, I cannot reproduce it consistently. I've googled a bit, but not much results. So, I decided to create a question here on SO.
推荐答案
直接来自 Apple的文档 c> UIImage imageNamed::
Straight from Apple's documentation on UIImage imageNamed:
:
您不能假设此方法是线程安全的。
You can not assume that this method is thread safe.
加载 UIImage
对象时,您必须在主线程上。你可以在任何线程上使用它们,但加载它们需要主线程。
You must be on the main thread when loading UIImage
objects. You can be on any thread when using them, but loading them requires the main thread.
这篇关于[UIImageAsset retain]:发送给deallocated实例的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!