Why is my cocoa program getting EXC_BAD_ACCESS during startup?

10,515

Solution 1

I've seen times where this can happen when you are trying to access a object that you didn't retain properly so its either not pointing to a valid copy of your object or its pointing to an object of another type. Placing breakpoints early and analyzing the objects as you step through startup using po and print in gdb is your best bet.

Solution 2

This is typically indicative of a memory management error.

Make sure all your outlet declarations follow best practice:

@interface MyClass : MySuperclass {
    UIClass *myOutlet;
}
@property (nonatomic, retain) IBOutlet UIClass *myOutlet;
@end

This format ensures that you get memory management right on any platform with any superclass.

Check any awakeFromNib methods to ensure that you're not over-releasing objects etc.

Solution 3

A new answer to an old thread... in XCode 4 the most effective way to diagnose EXC_BAD_ACCESS exceptions is to use Instruments to profile your app (from XCode click Product/Profile and choose Zombies). This will help you identify messages sent to deallocated objects.

Share:
10,515
AlanKley
Author by

AlanKley

I'm an Android developer converted from a Windows Stack Desktop developer. I enjoy developing my personal projects using Flutter

Updated on June 05, 2022

Comments

  • AlanKley
    AlanKley almost 2 years

    During the load of my cocoa application, my program crashes with the messsage EXC_BAD_ACCESS. The stack trace is not helpful. Any clues to how I can find the problem?