Search code examples
iosxcode5grand-central-dispatchnsmanagedobjectcontext

NSMangagedObjectContext getting a converted to String with a value of the DB path


I have an application that uses dispatch_queue_t and has been working fine for most users across OS/Device combinations. I have many threads that keep running and have a dispatch_queue_t running to fetch certain data. To keep track of NSManagedObjectContexts between threads, I use a NSDictionary that keeps track and maps the NSManagedObjectContext to the right thread.

Now the problem is on a long running queue, that is used to fetch data from the server and hence takes time, the NSManagedObjectContext reference in the dictionary changes to a String with value the path pointing to the database.

The only time I remove the object from the dictionary is on threadExit delegate, so the reference is never removed its just that the NSManagedObjectContext reference changes to a String (pointing to the DB file).

What could be causing this?


Solution

  • Yikes! Stupid oversight.

    Somewhere deep in the code, after the context was added to the Dictionary, it was being released. Now, why the context was changing to a string rather than just crash is a mystery.