Technical Q&A QA1367

Finding EXC_BAD_ACCESS bugs in a Cocoa project

Q:  How do I find EXC_BAD_ACCESS bugs in a Cocoa project?

A: How do I find EXC_BAD_ACCESS bugs in a Cocoa project?

This kind of problem is usually the result of over-releasing an object. It can be very confusing, since the failure tends to occur well after the mistake is made. The crash can also occur while the program is deep in framework code, often with none of your own code visible in the stack.

Summary

To avoid problems like this, you must follow the Cocoa memory management rules. Refer to ADC's document "Memory Management Programming Guide for Cocoa". The section “Object Ownership and Disposal” describes the primary policy.

Important Factors

Technical Documentation

For information on a debugging tool called NSZombieEnabled to help isolate this kind problem, as well as other debugging tips, refer to:

Technical Note 2124 Mac OS X Debugging Magic

This topic is also mentioned in the ADC Reference Library documentation:

Memory Management Rules

For an overview of Cocoa objects and their life cycles refer to the following guide:

The Life Cycle of a Cocoa Object



Document Revision History


DateNotes
2006-10-10

New document that discusses how to find memory protection violations or EXC_BAD_ACCESS bugs in Cocoa projects.