views:

798

answers:

1

Hi there,

I keep getting a -> Program received signal: “EXC_BAD_ACCESS”.

In the following code but I don't really understand why.

If I comment out the "executeFetchRequest" lines it goes away.

Shouldn't the [results release]; be all that's required?

Thanks in advance, Matt

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    // fetch the delegate
    TestingAppDelegate *app = (TestingAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *managedObjectContext = [app managedObjectContext];

    // construct the request
    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; 
    [request setEntity:[NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext]]; 

    NSError *error;
    NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
    [results release];
}
+2  A: 

I believe results, the result of executeFetchRequest:error:, should already be autoreleased. Because you are explicitly calling [results release], you're over-releasing that object when the current autorelease pool is drained. Remove the [results release] line and see if that fixes it.

pix0r
Thanks. That fixed it! Cheers.
Sway