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
OK, obviously, the problem is that the source is the release of an already released object (here is Hotcategoryviewcontroller) so basically it can be located where the error occurred, what the wrong object is, but in many cases, this is not enough. The next step is to see in concole the entire life cycle of the current instance from Alloc to free through the debug commands of gdb in Concole: Shell malloc_history app_pid object_ Instance corresponds to our example: 2011-10-27 15:12:40.061 ialiexpress[177:707] * * *-[hotcategoryviewcontroller settitle:]: Message Sent to deallocated instance 0x3a89c0 here should be entered: Shell malloc_history 177 0x3a89c0 where App_pid is the current process number (if you are debugging with the simulator, no problem; If you are debugging with a real machine , sorry, you see the process number is on the phone, you do not use it here), Object_instance is the ID of the instance object. You'll get this information after you enter.
Finally, hopefully the printed information will help you (in most cases, help you locate the problem). From: http://www.1000phone.net/thread-6921-1-2.html
(RPM) Exc_bad_access exception analysis for IOS development