问题
A line
UIImage *tempImage = [UIImage imageNamed:@"gradient-image"];
gets executed inside an NSOperation, on the background thread. The code breaks here with the message:
[UIImageAsset retain]: message sent to deallocated instance
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.
回答1:
Straight from Apple's documentation on UIImage imageNamed:
:
You can not assume that this method is thread safe.
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.
来源:https://stackoverflow.com/questions/28544201/uiimageasset-retain-message-sent-to-deallocated-instance