views:

123

answers:

1

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.

+3  A: 

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.

coneybeare
From the reading and testing I have done it appears the object is held memory as long as there is at least one pointer to the object. If I store the object id the object is autoreleased and the context is free to release it if necessary.Am I missing something?
Kevin
Yes you are missing the fact that core data will drop the "contents" of the `NSManagedObject` as needed to free up memory. For example, if you have a list of 10,000 `NSManagedObject` instances, they won't all be in memory. Only the ones you are using *right now* will be. Lastly, memory optimization at this level should be done later, *much* later, in the app development cycle; generally when you know you have a problem rather than trying to pre-optimize.
Marcus S. Zarra
So the contents will be dropped even if there is a pointer to the object? I guess my question was wrong. I will repost.http://stackoverflow.com/questions/2797298/how-does-core-data-determine-if-an-nsobjects-data-can-be-dropped
Kevin