Updating an Object Using a Kernel Data Transfer Message for an Exempt Instance

I am experiencing the strangest error trying to update values ​​for entities. I'm new to master data, so maybe something stupid ...

here is my update code:

-(BOOL)trataTarefa:(TarefaMap*) mapa{ NSFetchRequest *request =[[NSFetchRequest alloc] init]; NSManagedObjectContext *context = [[DataSource sharedManager]managedObjectContext]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tarefa" inManagedObjectContext:context]; [request setEntity:entity]; NSPredicate *predicate; predicate = [NSPredicate predicateWithFormat:@"cd_tarefa == %@ AND cd_instalacao contains[cd] %@ ", mapa.cd_tarefa, mapa.cd_instalacao]; [request setPredicate:predicate]; NSError *error=nil; NSArray *result = [context executeFetchRequest:request error:&error]; [request release]; NSLog(@"result=%d",[result count]); if([result count]==1){ if (mapa.tp_operacao ==3){ Tarefa* tarefa = [result objectAtIndex:0]; [tarefa setTp_operacao:[NSNumber numberWithInt:3]]; NSLog(@"Tarefa=%@", tarefa); NSError* saveError=nil; if (![context save:&saveError]) { NSLog(@"Saving changes to book book two failed: %@", saveError); } else { NSLog(@"Teoricamente gravou...") ; } } } return YES; 

}

the code works, it saves the records, but returns the message * - [CFNumber release]: the message sent to the freed instance ##### tracking it using shell malloc_history, I get:

 Date/Time: 2011-03-24 14:12:01.988 -0300 OS Version: Mac OS X 10.6.6 (10J567) Report Version: 7 ALLOC 0x6603f60-0x6603f6f [size=16]: thread_a052f540 |start | main | UIApplicationMain | -[UIApplication _run] | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSource1 | __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ | PurpleEventCallback | _UIApplicationHandleEvent | -[UIApplication sendEvent:] | - [UIApplication handleEvent:withNewEvent:] | -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] | - [UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:] | -[UIStatusBar requestStyle:animated:] | -[UIStatusBar requestStyle:animationParameters:] | - [UIStatusBarWindow setCornerStyle:] | -[UIImageView initWithImage:] | -[UIImageView setImage:] | -[UIImageView(UIImageViewInternal) _updateState] | - [UIImageView(UIImageViewInternal) _canDrawContent] | -[UIView(Rendering) contentMode] | +[NSNumber numberWithInt:] | -[NSPlaceholderNumber initWithInt:] | CFNumberCreate | _CFRuntimeCreateInstance | malloc_zone_malloc Binary Images: 0x1000 - 0x5cff3 +Nonononono (??? - ???) <C4B33680-F374-3E37-9C91-6DEDE06C4701> /Users/marsson/Library/Application Support/iPhone Simulator/4.1/Applications/B13321A3- 1E73-4DC0-8E37-E2E56116ECEA/Nonononoo.app/Nnonononononono 

What I can take from this log is that the object is not actually freed ... I already tried to update the object using setValue: forKey with the same result ... if I comment out a line in the update, the code starts, but Of course, the object is not updated. Has anyone had a similar problem?

Thanks in advance!

+4
source share
2 answers

Actually it was a problem with a stupid thread ... I tried to update the ManagedContext from the background thread, and this sometimes caused the application to crash. When I used a different managed context and used the notification center to synchronize the context, everything went smoothly. Thanks everyone for the suggestions ...

+1
source

Looks like a problem with [tarefa setTp_operacao:]. Can you post the code in the Tarefa class? The NSNumber created is auto-implemented, so if Tarefa does not save it when you run setTP_operacao, you will gain access to the remote object after the autoplay pool is issued (possibly at the end of the current user interface event).

0
source

Source: https://habr.com/ru/post/1345134/


All Articles