title: Odd Core Data error caused by over releasing?
body: <p>Occasional reader and first time question asker, so please be gentle :)</p>
  
  <p>I am creating a <strong>Managed Object</strong> (Account), that is being passed into a child view controller where its being set in a property that is retained.</p>
  
  <pre><code>Account * account = [[Account alloc] initWithEntity:entity insertIntoManagedObjectContext:context];
  AddAccountViewController *childController = [[AddAccountViewController alloc] init];
  childController.title = @"Account Details"; 
  childController.anAccount = account;
  childController.delegate = self;
  
  [self.navigationController pushViewController:childController animated:YES];
  [childController release];
  [account release];
  </code></pre>
  
  <p>The view controller interface:</p>
  
  <pre><code>@interface AddAccountViewController : UIViewController {
  }
  
  @property (nonatomic, retain) IBOutlet UITextField * usernameTextField;
  @property (nonatomic, retain) IBOutlet UITextField * passwordTextField;
  
  @property (nonatomic, retain) Account * anAccount;
  @property (nonatomic, assign) id &lt;AddAccountDelegate&gt; delegate;
  
  - (IBAction)cancel:(id)sender;
  - (IBAction)add:(id)sender;
  - (IBAction)textFieldDone:(id)sender;
  @end
  </code></pre>
  
  <p>So in code sample 1 I've released the account object because I am no longer interested in it in that method. As it is retained by the <strong>AddAccountViewController</strong> I have an entry in <strong>AddAccountViewController</strong>'s <strong>dealloc</strong> that releases it.</p>
  
  <p>However when I go to delete the object from the <strong>ManagedObjectContext</strong> the app crashes with the following (rather unclear) error:</p>
  
  <pre><code>Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
  _Unwind_Resume called from function _PFFaultHandlerLookupRow in image CoreData.
  </code></pre>
  
  <p>After much debugging &amp; hair pulling I discovered that if I don't release account in <strong>AddAccountViewController</strong>'s <strong>dealloc</strong> method the app works properly continually and doesn't appear to leak according to Instruments.</p>
  
  <p>Can anyone shed any light as to whats going on? I understand from the docs on properties that those retained need to be released. What have I missed?</p>
  
  <p><strong><em>Update to answer Kevin's question</em></strong></p>
  
  <p>The code to delete the object from the <strong>ManagedObjectContext</strong> is in the  RootViewController (that holding the child controller)</p>
  
  <pre><code>// Override to support editing the table view.
  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  
      if (editingStyle == UITableViewCellEditingStyleDelete) {
          // Delete the managed object for the given index path
          NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
  
          [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
  
          // Save the context.
          NSError *error = nil;
          if (![context save:&amp;error]) {
              /*
               Replace this implementation with code to handle the error appropriately.
  
               abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
               */
              NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
              abort();
          }
      }  
  }
  </code></pre>