Here's my situation:
My app includes a Core Data type (call it ThingerImage) which holds some large, expensive NSData objects. They take a while to generate, and I don't want that slowing the UI, so I do something like this:
1 Main thread: request ThingerImage
2 Background thread: create ThingerImage
3 Background thread: call [NSManagedObjectContext save:]
4 Background thread: pass objectID of newly created ThingerImage back to main thread
5 Main thread: attach ThingerImage to its parent Thinger
As the docs recommend, I have a different NSManagedObjectContext for each thread, sharing the same NSPersistentStoreCoordinator underneath. And as the docs recommend, I only pass NSManagedObjectIDs between threads.
The puzzling thing is, I sometimes get a NSObjectInaccessibleException during step 5:
CoreData could not fulfill a fault for '0x13dbe0 <x-coredata://53821256-6669-4D90-8D99-A3C99185AAC1/ThingerImage/p2053>'
At first I thought perhaps step 3 was failing silently. But then I found that when I get this error, I can simply pause for one second, then retry step 5, and it works. Yikes!
This suggests that there's some kind of race condition in my code. I'm guessing that either Core Data or sqlite itself writes out large rows asynchronously, and [NSManagedObjectContext save:] returns before it's truly done. Anybody know if this is the case? Any other theories?
Cheers,
Paul
--
You received this message because you are subscribed to the Google Groups "iphonedevmn" group.
To post to this group, send email to iphon...@googlegroups.com.
To unsubscribe from this group, send email to iphonedevmn...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonedevmn?hl=en.
--
You received this message because you are subscribed to the Google Groups "iphonedevmn" group.
To post to this group, send email to iphon...@googlegroups.com.
To unsubscribe from this group, send email to iphonedevmn...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonedevmn?hl=en.
(1) NSManagedObjectContextDidSaveNotification is always fired during context save, not at some later time after the save completes. I though using the notification might be causing your code to wait for a long-running asynchronous operation to complete, but that seems not to be the case.
(2) Calling processPendingChanges on the receiving thread may well be the key, although I couldn't get that alone to fix my issue. You said the refresh was also necessary, but in may case, the big objects are created for the first time on the background thread, and I'm getting objects that are too *new* and reference big rows that aren't saved yet. So it sure seems lik the refresh shouldn't be necessary.
--
You received this message because you are subscribed to the Google Groups "iphonedevmn" group.
To post to this group, send email to iphon...@googlegroups.com.
To unsubscribe from this group, send email to iphonedevmn...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonedevmn?hl=en.
That's all remarkably similar to my situation, and the symptoms I'm seeing. Yes, I'm getting the updated parent object but not its association. So maybe refreshObject: is critical, although that sure seems fishy: why should I need to refresh a parent to get its association?
Regardless, I'm now a bit down the road of using files, and having much better luck. I'll post some code once I have it working smoothly.