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 destroyed when it is converted to _nszombie, after setting nszombieenabled, when you send a message to an object that has been disposed of, Instead of crash or creating an incomprehensible behavior, this object emits an error message and then disappears in a predictable way that produces a debug breakpoint , so we can find out exactly which object is being released incorrectly.
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.
Alternatively, you can check the Enable zombieobjects directly in the Diagnostics Settings window in the Xcode4 menu Product, Editscheme, Xcode can be used to cmd+shift+< into this window.