开发者

How to treat CoreData entities with low memory usage

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 tr开发者_C百科eat them in a low memory usage.

Thank you.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜