Reputation: 4780
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?
Upvotes: 3
Views: 10547
Reputation: 13457
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.
Upvotes: 1
Reputation: 8161
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.
Upvotes: 2
Reputation:
Check console log ( Applications/Utilities/Console.app ) . When program crashes on startup, and there's something wrong with initialization, it often writes out some helpful error messages there, before it crashes.
Upvotes: 0
Reputation: 1077
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.
Upvotes: 5
Reputation: 6589
To add: the foremost reason for unarchiving failure is forgetting "return self;" from the -init of a custom class. It hurts a lot :(
Upvotes: 0
Reputation: 4780
This is one possible reason. There is a IBOutlet object that isn't being initialized and a message is being invoked on nil. The stack trace might look like this:
#0 0x90a594c7 in objc_msgSend
#1 0xbffff7b8 in ??
#2 0x932899d8 in loadNib
#3 0x932893d9 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]
#4 0x9328903a in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:]
#5 0x93288f7c in +[NSBundle(NSNibLoading) loadNibNamed:owner:]
#6 0x93288cc3 in NSApplicationMain
#7 0x00009f80 in main at main.mm:17
Since the stack trace is not helpful you will have to step through your code to find the error. If for some reason you aren't able to set breakpoints early in your execution, try inserting some Debugger(); calls which will break to the debugger.
Upvotes: -3