Нечетно Ошибка основных данных, вызванная чрезмерным выпуском?

Случайный читатель и впервые задающий вопрос, поэтому, пожалуйста, будьте осторожны :)

Я создаю управляемый объект (учетную запись), который передается в дочерний контроллер представления, где он устанавливается в сохраняемом свойстве.

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];

Интерфейс контроллера представления:

@interface AddAccountViewController : UIViewController {
}

@property (nonatomic, retain) IBOutlet UITextField * usernameTextField;
@property (nonatomic, retain) IBOutlet UITextField * passwordTextField;

@property (nonatomic, retain) Account * anAccount;
@property (nonatomic, assign) id <AddAccountDelegate> delegate;

- (IBAction)cancel:(id)sender;
- (IBAction)add:(id)sender;
- (IBAction)textFieldDone:(id)sender;
@end

Итак, в примере кода 1 я выпустил объект account, потому что он меня больше не интересует в этом методе. Поскольку он сохраняется в AddAccountViewController , у меня есть запись в AddAccountViewController dealloc , которая освобождает его.

Однако когда я иду удалить объект из the ManagedObjectContext приложение вылетает со следующей (довольно непонятной) ошибкой:

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.

После долгой отладки и выдергивания волос я обнаружил, что если я не освобожу учетную запись в AddAccountViewController dealloc приложение работает должным образом постоянно и не имеет утечки согласно Instruments.

Может ли кто-нибудь пролить свет на то, что происходит? Из документации по свойствам я понимаю, что оставшиеся необходимо освободить. Что я пропустил?

Обновление, чтобы ответить на вопрос Кевина

Код для удаления объекта из ManagedObjectContext находится в RootViewController (который содержит дочерний контроллер)

// 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:&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();
        }
    }  
}
6
задан tarasis 12 September 2010 в 10:14
поделиться