Detailed explanation of the essence of exc? Bad? Access and the debugging principle of Zombie mode



What is exc? Bad? Access and how to debug it

Sometimes, you will encounter a crash caused by exc? Bad? Access. This article will tell you what exc? Bad? Access is and why it is produced. I will also provide some solutions for exc? Bad? Access errors.

1. What is exc? Bad? Access?

Once you understand the essence of exc? Bad? Access, you will better understand this vague term. Here is a very simple explanation, but also a technical explanation. Let’s start with a simple explanation.

2. Simple explanation

Whenever you encounter the error “exc” bad “access, it means that you send a message to a released object. This is the most common case, but there are exceptions, which we will discuss later.

3. The essence of exc? Bad? Access

The technical explanation is somewhat complicated. In C and Objective-C, you’re dealing with pointers all the time. A pointer is nothing more than a variable that stores the memory address of another variable. When you send a message to an object, a pointer to that object is referenced. This means that you get the memory address indicated by the pointer and access the value of the storage area.

When the memory area is no longer mapped to your application, or in other words, the memory area is not used when you think it is used, the memory area is inaccessible. At this point, the kernel will throw an exception (exc) indicating that your application cannot access the memory area (bad access).

In short, when you encounter exc? Bad? Access, this means that you are trying to send a message to a memory block that cannot execute the message. However, in some cases, exc? Bad? Access is caused by a corrupted pointer. Whenever your application tries to reference a bad pointer, an exception is thrown by the kernel.

4. Debug exc? Bad? Access

Debugging exc? Bad? Access can be tricky and frustrating. However, now exc? Bad? Access is no longer a mystery, it is not as terrible as you think.

The first thing you need to know is that your application doesn’t have to be at the point of crash, unable to access memory areas. This is the reason why debugging exc? Bad? Access is often difficult.

The same is true for damaged pointers. When your pointer is damaged, your application will not crash. At the same time, if you pass a damaged pointer back and forth in the application, it will not crash. A crash occurs when an application tries to reference a damaged pointer.

5. Zombie debugging mode

Zombie debugging patterns have gained popularity in the past few years, and in fact they have been on Xcode for more than a decade. Zombies sound a bit dramatic, but they are actually a great name for helping us debug the exc ABCD access function. Let me explain how it works.

In Xcode, you can enable zombie objects, which means that the released objects will be preserved as zombies. In other words, the object released is reserved for debugging. There is no magic involved here. If you send a message to a zombie object, your application will crash due to exc? Bad? Access.

Is there any good in this? The reason for making exc ABCD access hard to debug is that you don’t know which object your application is trying to access. Zombie objects solve this problem in many cases. By keeping the released objects, Xcode can tell you which object you are trying to access, which makes it much easier to find the cause of the problem.

It’s easy to enable zombie objects in Xcode. Note that this may vary depending on the version of Xcode for. For Xcode 6 and 7, click Edit scheme in the upper left corner and select Edit scheme.

Check run on the left and open the diagnostics option on the top. To enable zombie objects, check the enable zombie objects box.


If you now encounter exc? Bad? Access, output in the console of Xcode, and tell you where to find the problem. Take a look at the following example output.

-[ChildViewController respondsToSelector:] message sent to deallocated instance 0x17579780


In the above example, Xcode tells us that the message of the respondstoselector is sent to a zombie object. However, the zombie object is no longer an instance of the childviewcontroller class. The memory area previously allocated to the childviewcontroller instance is no longer mapped to your application. This gives you a good idea of the root cause of the problem.

Unfortunately, the zombie object will not be able to save a record of every crash of exc ABCD access in your day. Since zombie objects don’t have these methods, you can take other methods to do some proper analysis.

6. analysis

If zombie objects can’t solve your problem, the root cause of the problem may not be so simple. In this case, you need to take a closer look at the code that executes when the application crashes. This can be cumbersome and time-consuming.

To help you find problems with your code, you can use Xcode to analyze your code and help you find the problems. Note that Xcode analyzes the project and points out every potential problem.

Use Xcode to analyze your project. It will take a moment to select analyze from Xcode’s product menu or press shift-command-b.xcode, but when it is finished, you will see the list of questions in the issue navigator on the left. Problems found by analyze are highlighted in blue.


When you click on a question, Xcode will point to the question code block, which is exactly what you need to pay attention to. Note that Xcode is just a suggestion. In some cases, this is possible. The problem is irrelevant and not fixed.


If you can’t find the error that caused exc? Bad? Access, you need to carefully examine the Xcode project and analyze every problem found in it.


7. conclusion

Exc? Bad? Access is a common problem faced by developers. It is an inherent problem of manual memory management. Although the implementation of arc memory management (automatic reference counting) makes exc ﹣ bad ﹣ access less frequent, they do not really disappear.