Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hang on NSManagedObjectContext's save:

For some reason sometimes my app will just hang with the following code:

NSError *error;
if (![self.managedObjectContext save:&error]) {
     NSLog(@"Couldn't save: %@", [error localizedDescription]);
}

It doesn't always hang, just sometimes. If I break on all exceptions then Xcode will break on the save call, but if I turn off breakpoints it will just hang forever, no crashes or anything.

Any ideas?

like image 491
edc1591 Avatar asked Jan 27 '12 03:01

edc1591


1 Answers

Hanging on anything that uses ManagedObjectContext is a sign of a deadlock. Either use NSLocking protocol or create a new MOC for each thread and synchronize them.

Another useful doc from Apple -> Concurrency with Core Data

like image 81
Piotr Byzia Avatar answered Oct 04 '22 21:10

Piotr Byzia