偶尔阅读器和第一次的问题提问者,所以请温柔:)过度释放引起的奇数核心数据错误?
我创建一个管理对象(账户),正在传递到哪里它在这是一个属性被设置子视图控制器保留。
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在我发布的帐户对象,因为我在那个方法已经不再感兴趣。由于它保留AddAccountViewController我有一个条目AddAccountViewController的dealloc它释放它。
但是当我去从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方法该应用程序正常工作,并不会泄漏根据仪器。
任何人都可以说明发生了什么?我从文档中了解到那些保留的内容需要发布。我错过了什么?
更新回答凯文的问题
的代码从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();
}
}
}
可以显示从NSManagedObjectContext中删除它的代码吗?这是否发生在AddAccountViewController或其他地方? – 2010-09-12 09:53:47
'childController.anAccount = account;'此行不保留'account'。它将它复制到'anAccount'。这根本不+1 +1它的保留,你只需要在'AddAccountViewcontroller'的dealloc方法中释放'anAccount'。 – 2010-09-12 10:07:16
@Thomas:'@property(nonatomic,retain)Account * anAccount;'为什么不保留? – Pyetras 2010-09-12 10:17:06