Is it better to store an NSArray of NSManagedObjects or NSManagedObjectIDs?
In my application I need to keep track of a list of objects that are being displayed. Right now I have an NSArray with all of the NSManagedObjects. Would I be better off to store the ObjectIDs and then only request the object when I need it?
I开发者_开发知识库 am mainly concerned about memory at this point.
I am mainly concerned about memory at this point.
The first issue here is that you don't really understand how memory is stored. This array of yours is only holding pointers to the objects, not the objects themselves, thus holding the NSManagedObjects vs ObjectIDs is the same as the size of pointers are the same.
CoreData is pretty developed and has many internal optimizations for automatic memory handling and faulting within the Managed Object Context.
Given this info, it seems the clear choice is to use NSManagedObjects in your array solely because doing it the other way adds no benefit, and doing it this way has you write less code to retrieve them.
精彩评论