Core Data - How to check if a managed object's properties have been deallocated?

Posted by georryan on Stack Overflow See other posts from Stack Overflow or by georryan
Published on 2010-04-13T01:17:46Z Indexed on 2010/04/13 1:22 UTC
Read the original article Hit count: 331

I've created a program that uses core data and it works beautifully.

I've since attempted to move all my core data methods calls and fetch routines into a class that is self contained. My main program then instantiates that class and makes some basic method calls into that class, and the class then does all the core data stuff behind the scenes. What I'm running into, is that sometimes I'll find that when I grab a managed object from the context, I'll have a valid object, but its properties have been deallocated, and I'll cause a crash. I've played with the zombies and looked for memory leaks, and what I have gathered is it seems that the run loop is probably responsible for deallocating the memory, but I'm not sure.

Is there a way to determine if that memory has been deallocated and force the core data to get it back if I need to access it? My managedObjectContext never gets deallocated, and the fetchedResultsController never does, either.

I thought maybe I needed to use the [managedObjectContext refreshObject:mergeData:] method, or the [managedObjectContext setRetainsRegisteredObjects:] method. Although, I'm under the impression that last one may not be the best bet since it will be more memory intensive (from what I understand).

These errors only popped up when I moved the core data calls into another class file, and they are random when they show up.

Any insight would be appreciated.

-Ryan

© Stack Overflow or respective owner

Related posts about core-data

Related posts about memory-deallocation