[UINavigationController retain]: message sent to deallocated instance

前端 未结 3 1842
礼貌的吻别
礼貌的吻别 2021-01-20 11:07

My application crashes when simulating Memory warning in simulator with error:

[UINavigationController retain]: message sent to deallocated instance<

3条回答
  •  感动是毒
    2021-01-20 11:54

    It is likely you are using an assign or __unsafe_unretained property somewhere in your code. Delegates should always be of type weak, so that the reference to the delegate object is nil'ed out on deallocation.

    Also, calling:

    [((WPRAppDelegate*) [UIApplication sharedApplication].delegate) startWithFlash];
    

    ... from within another class in your app is a bit of a smell. One that I've had many times. It means you have circular dependencies. Your app delegate is dependent on the class using this code (transitively, if not directly), and this class is dependent on your app delegate. Looking at your Instruments trace, it looks like you have adopted the delegate pattern else where, so you have some experience with decoupling. I would suggest bubbling that message up through a delegate chain, notification, or block.

提交回复
热议问题