iphone: memory problems after refactor

Posted by agilpwc on Stack Overflow See other posts from Stack Overflow or by agilpwc
Published on 2010-06-14T04:33:59Z Indexed on 2010/06/14 4:42 UTC
Read the original article Hit count: 194

I had a NIB with several view controllers in it. I modified the code and used Interface Builder decomose interface to get all the view controllers in their own Nib. But now with empty core data database, I'm getting "message sent to deallocated instance" errors. Here is the code flow: From the RootViewController this is called:

 if (self.dogController == nil) {
        DogViewController *controller = [[DogViewController alloc]    initWithNibName:@"DogViewController" bundle:nil];
        self.dogController = controller;
        [controller release];
    }
    self.dogController.managedObjectContext = self.managedObjectContext;
    [self.navigationController pushViewController:self.dogController animated:YES];

Then in a dogController a button is pressed to insert a new object and the following code is excuted and the error hits on the save, according to the trace

NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
    NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];

    // If appropriate, configure the new managed object.
    [newManagedObject setValue:[NSDate date] forKey:@"birthDate"];
    [newManagedObject setValue:@"-" forKey:@"callName"];

    // Save the context.
    NSError *error = nil;

     if (![context save:&error]) {

Then the error produced in the console is

* -[JudgeViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x598e580

I'm racking my brain for hours and I can't figure out where my minor changes made something messed up. Any ideas?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about memory-management