views:

378

answers:

2

Hi guys,

the second time I execute

[[MOC executeFetchRequest:request error:&error] lastObject];

after having said

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Login" inManagedObjectContext:MOC]];
NSError *error = nil;

it crashes with a EXC_BAD_ACCESS. Included is the debug window, and it looks like the crash happens deep down in the Core Data stack. Any idea on how I should go about debugging this to find out what's going on?

alt text

(just in case, here's the link to the picture http://tinypic.com/r/zmavph/6 Click on the picture in the link and the debug window will get larger)

Cheers

Nik

+2  A: 

EXC_BAD_ACCESS is a memory error. You are using an object after deallocating it. It would be difficult to debug this without (more) code.

Have you tried running the analyzer (Xcode > Build > Build and Analyze)?

You may also want to break out the fetch and array lookup:

NSArray *fetchedObjects = [MOC executeFetchRequest:request error:&error]
if (!fetchedObjects) {
    NSLog(@"Error fetching Login: %@", [error localizedDescription]);
    abort();
}

NSManagedObject *loginObject = [fetchedObjects lastObject];
gerry3
As gerry3 suggested this is not a Core Data issue but a simple over-release of an object. Try turning on NSZombie and tracking down the over-released object.
Marcus S. Zarra
A: 

Apple has a very useful page on CoreData debugging.

Ben Gottlieb