iOS Development Note----exc_bad_access (code=1, address=0x789870) Wild pointer error, suspended animation debug state

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.