Cause of Error:
Exc_bad_access (code=1, address=0x789870) Wild pointer error, the main reason is that when an object is completely released, that is, Retaincount, the reference count is 0. A wild pointer error occurs when another method is called by the object.
For example:
Person *jerry = [[Person alloc]init]; Retaincount reference count is 1
[Jerry Eat]; Call the Eating method
[Jerry Release]; Release Jerry This object to the Retaincount reference count of 0
At this point, if you continue to reference Jerry This object will have a wild pointer error, exc_bad_access
[Jerry Sleep];
Workaround:
First of all to locate where the presence of such a wild pointer reference error, if it is a large project code size, it is very painful to find.
iOS provides an environment variable setting to help locate the information description for the wrong location: nszombieenabled , that is, when the nszombieenabled environment variable is set, an object is converted to _nszombie when it is destroyed. When you set nszombieenabled, when you send a message to an object that has already been disposed of, the object does not crash or create an incomprehensible behavior, but instead emits an error message and disappears in a predictable way that produces a debug breakpoint. So we can find specific or presumably which object has been wrongly released.
For example, a hint like this would appear:
[Jerry Sleep]:message sent to deallocated instance 0x78d7ed0
Set the nszombieenabled environment variable, in XCODE4:
You can click the Xcode4 menu Product, Edit scheme-> Arguments, and then click "Plus" to add the nszombieenabled parameter to the Environment Variables window, followed by the number Write "YES" on the value.
Or, in the Xcode4 menu Product, Editscheme, Diagnostics Settings window, simply tick enable zombieobjects, Xcode can be cmd+shift+< into this window.