My application crashes when simulating Memory warning in simulator with error:
[UINavigationController retain]: message sent to deallocated instance<
Quickfix: insert assert([NSThread isMainThread]);
to various places in your code where you access appDelegate.window.rootViewController
. This should be done for write- and for read-accesses to the property! This will reveal the culprit. appDelegate.window.rootViewController
must not be accessed from any other thread than the main thread.
Generally, there are these reasons why this may happen:
__unsafe_unretained
variables.unsafe_unretained
property.nonatomic
, non-weak
property from different threads at the same timeThe fix for 1 and 2 is simple: Just don't use unsafe_unretained
anymore.
The fix for 3 is: use ARC instead.
The fix for 4 and 5: use atomic
properties instead, or synchronize access to your iVars. (Note that you must not access iVars from atomic properties directly as this breaks the atomicity.) Alternatively, use the property only from one thread, e.g. only from the main thread.
In your example, I assume that issue #5 applies. The culprit should be some non-main-thread accessing rootViewController
from UIWindow
.