One: Exc_bad_access Exception Introduction
In the process of debugging Objective-c program, the phenomenon of the program crash is unavoidable, but most of the errors can be solved by displaying the wrong reason combined with the NSLog way. such as Nsinvalidargumentexception (the name can see what is wrong), and so on, there is still a debug this killer. But exc_bad_access this exception is too difficult to deal with, the name can not see what is the reason, the other hints are not, debug are uncertain.
Let's introduce the following exc_bad_acces: This exception is basically caused by improper memory use, and 90% of the error source is the release of an already released object.
Two: Analysis method
Add the nszombieenabled environment variable to the project runtime and set it to Enabled, and when exc_bad_access occurs, XCode's Console prints a description of the problem. and add both the mallocstacklogging and MALLOCSTACKLOGGINGNOCOMPACT environment variables to enable malloc logging
Three: Output information
As soon as you add the nszombieenabled variable, the exc_bad_access will print out the wrong reason in Concole, and most of the information will appear
Run the code, the following crashes appear below we open the "Activity Monitor" to find our corresponding PID, our target is Hpthememanager, As long as the hpthememanager corresponding PID can be found (Hpthememanager is downloaded in the forum, is looking at the code, directly to take him to do the experiment) now, We got two main messages: Process id:50127 crash Address: 0x6d564f0 We open the terminal and enter the following command: [Code]C#/CPP/OC Code:
1 |
sudo malloc_history 50127 0x6d564f0 |
The results are shown as:
So that we can navigate to this line of code, turn from: http://www.1000phone.net/thread-6921-1-2.html
Exc_bad_access Exception Analysis for IOS development