I'm developing an iphone app and when I turn on my NSZombieEnabled I have regularly a crash on error :
*** -[CALayer retain]: message sent to deallocated instance 0xe6012e0
It always come when I push or pop a view in my view controller. Sometimes there's this error before :
-[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
What does it mean? Anyone has a clue or has encountered this problem?
Thank you very much for help!
Romain
This likely means you are trying to retain an object a UI object, such as a UIButton, that was released. There are a number of ways to track down this issue but if you can narrow down where this is occurring in your app, I generally start commenting out releases until I see where the problematic release is. My guess is you released something that was autoreleased.
If the above answers did not help then check if your code is using KVO in the class where you receive this error. When KVO is sending a message to your observing class about a value on a key changing, if the class has been released by ARC then KVO will be trying to alert a non-existent address in memory about that changes, causing your app to throw this error.
Consider this, a class called MyViewController
and you want to observe when the bounds
property of it's view.layer
changes indicating a layout change from landscape to portrait. So you add the line:
// self is MyViewController
self.view.layer.addObserver(self, forKeyPath: "bounds", options: .new, context: nil)
This will alert your class if the view
size changed.
But if your viewController is dismissed, say a UINavigationController
pops it off the stack, KVO is still going to try and alert MyViewController
the view's bounds has changed (because now it's gone). Then when KVO does this your application is going to crash. In your debug console you would see the following message:
-[MyViewController retain]: message sent to deallocated instance
This is because you must remove the observer (MyViewController
) for that keyPath. It is best to do this before MyViewController
is dismissed, ike so:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.view.layer.removeObserver(self, forKeyPath: "bounds")
}
Now when you attempt to pop MyViewController
from the navigation stack there will be no error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With