Thorsten Niehues
Thorsten Niehues

Reputation: 14452

How to debug EXC_BAD_ACCESS error using Profile in Xcode

After I received a exc_bad_access error I read this tutorial: http://www.ioslearner.com/debugging-exc_bad_access-error-xcode-instruments/ and followed the steps:

Everything looks the same on my computer except that I do not get the Zomie Signal.

In order to make sure I did not forget a step I tried it with the example code provided in the Tutorial. There I see the Zombi Signal

So how do I get the zombie signal in my project using Xcode -> Profile?

This is the sample code I use:

I am well aware that the two releases cause the error. Again the question is how get the "Zombie Message" in the Profile using Xcode:

NSArray *currentRestaurant = [restaurants objectAtIndex:i];
RestauInfo *restauInfo = [NSEntityDescription
                         insertNewObjectForEntityForName:@"RestauInfo" 
                         inManagedObjectContext:context];
[restauInfo release];
restauInfo.Name = [currentRestaurant objectAtIndex:0];
restauInfo.Cuisine = [currentRestaurant objectAtIndex:1];
NSError *error;
if (![context save:&error]) {
    NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
[restauInfo release];// - this release would cause an EXC_BAD_ACCESS

Another question is: Why do I get bad_access at the second release - and not when accessing restauInfo after the first release?

Upvotes: 0

Views: 4584

Answers (2)

Thorsten Niehues
Thorsten Niehues

Reputation: 14452

I found another way detecting faults in memory management:

In Xcode you can choose "Run", "Test", "Profile" and "Analyze"
(By pressing and holding the run Button in the upper left corner)

Running the analyze reveals memory management errors - such as

  • over releasing
  • leaks

Upvotes: 1

Antwan van Houdt
Antwan van Houdt

Reputation: 6991

You are overreleasing restauInfo, its an autoreleased object and you call -release manually twice, causing your crashes.

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSEntityDescription_Class/NSEntityDescription.html

Upvotes: 0

Related Questions