Slee
Slee

Reputation: 28268

popping to UIViewController causing crash - message sent to deallocated instance

I have a UIViewController I am showing as a Modal popover. When that view is done being used I am popping to a particular location in my UINavigationBar:

[[appDelegate.homeViewController navigationController] popToViewController:[[appDelegate.homeViewController navigationController ].viewControllers objectAtIndex:2] animated:YES];

The View Controller presenting the modal UIViewController is mentioned in the crash below:

*** -[ClientDetailsViewController respondsToSelector:]: message sent to deallocated instance 0x8c17650

How can I track this down and see what is causing my crash?

Upvotes: 0

Views: 905

Answers (1)

AliSoftware
AliSoftware

Reputation: 32681

How can I track this down and see what is causing my crash?

Simply activate Zombies.

  • In Xcode4, hold the alt key while choosing "Product" > "Run" from the menu to show the Schemes dialog (or choose Edit Schemes to show it).
  • Then in the "Diagnostics" tab, check the "Enable Zombie Objects" checkbox

Diagnostics Dialog Now when an object is used after it has been deallocated, you will be able to see which object is concerned and when it has been over-released.


Moreover, don't hesitate to use the static analyzer from the "Product" -> "Analyze" menu so that Xcode will tell you every memory management errors (and others) he can find in your code.

Static Analyzer example

You should always run this "Analyze" tool once in a while and fix ALL the warnings it displays, as it is a very good tool to tell you what may be wrong in your code and is of very good advice.

Not having any warning when you run this tool is not a guarantee that your code won't crash, but having warnings when you run this tool quite guarantee you the're something to be fixed in your code.

Upvotes: 3

Related Questions