views:

116

answers:

1

Hello,

I tried CoreData for iPhone app, but it's memory-hogging when entity instances are fetched. After they are released, memory usage doesn't decrease at all. Is there any way to treat them in a low memory usage.

Thank you.

A: 

Core data should handle memory warnings itself. You do not have to worry about them. It will fauly managed objects for you and refetch them as you need.

You can be proactive before you get to this state though.

You can use NSFetchRequet's setPropertiesToFetch: to limit the data you retrieve from the database. This will effectively make each managed object smaller in memory. You can reduce the size of your fetches by setting the number of entities fetched (setFetchLimit:) and finally, after you have some Managed Objects, you can proactively prune them from the object graph by sending the NSManagedObjectContext a refreshObject:mergeChanges: message. Specifically:

[myManagedObjectContext refreshObject:anObjectToRemoveFromMemory mergeChanges:NO];

Will turn anObjectToRemoveFromMemory into a fault.

Roger Nolan
Thank you. I'll try it.
Emmettoc