Odd Kernel Error Released Error?

Sometimes the reader and the first question are asked, so please be careful :)

I create a Managed Object (account), which is passed to the controller of the child view, where it is set in the saved property.

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

View Controller Interface:

 @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 

So, in code example 1, I released an account object because I am no longer interested in this method. Since it is saved by the AddAccountViewController , I have an entry in the AddAccountViewController dealloc that releases it.

However, when I go to remove the object from the ManagedObjectContext , the application crashes with the following (rather obscure) error:

 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. 

After a lot of debugging and hair pulling, I found that if I didn’t release the account in the AddAccountViewController dealloc method , the application worked correctly constantly and did not seem to flow according to the tools.

Can anyone shed light on what is happening? I understand from the docs about the properties that need to be saved. What did I miss?

Refresh to answer Kevin's question

The code for deleting an object from a ManagedObjectContext is in the RootViewController (which contains the child controller)

 // 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
ios objective-c iphone cocoa-touch core-data
source share
3 answers

First: it sounds like a bug in the Apple part. Core Data raises _Unwind_Resume , which (possibly) throws some sort of exception. An unwinding exception exists on the phone, but (I think) uses an ARM ABI, which uses function names starting with __cxa_ . Do you work on a simulator? What version of the SDK?

There may be an additional release floating around somewhere, “balanced” when you delete a call to [account release]; .

“Tools show no leaks” does not mean that they are not; the last time I checked, it got confused in loops (i.e. it will not show a leak if you forgot to disable IBOutlets in dealloc). I tested with NSMutableData * d = [NSMutableData dataWithLength:1<<20]; memcpy(d.mutableBytes, &d, 4); NSMutableData * d = [NSMutableData dataWithLength:1<<20]; memcpy(d.mutableBytes, &d, 4); , but a simpler test is just [[UIView alloc] initWithFrame:CGRectZero] .

If you think this is a save / release problem, I once debugged them, overriding the save / release / answering machine to call NSLog. Then I added breakpoints to all of them, ran them to run the bt command, and clicked the autocontinue button. Then run the thing that breaks (in my case, I think it's just an extra hold), print out the magazine output, paste it on the board and spend half an hour saving and releasing.

+1
source share

I had a similar problem ending with "An attempt was made to call a character in system libraries that are not on the iPhone: _Unwind_Resume called from the _PFFaultHandlerLookupRow function in the CoreData image." Error message.

My problem was the wrong "cascading" rule of deleting a relation in a model. With this rule, my top managed entity was deleted, but is still mentioned in the code. After installing the "delete rule" in this regard, "nulify" everything worked as it was designed.

-> there are no problems with kernel data ... a design problem!

Johnny

+1
source share

When you delete any managed object, the system automatically releases the entire link associated with this object. Thus, there is no need for a real object programmatically. Once you delete an object, you cannot access this object in the parent class.

0
source share

All Articles