Crashing issue due to memory management (using Core Data)

放肆的年华 提交于 2019-12-12 02:22:55

问题


I am using Core Data. From there i am retrieving 10000+ data

Using NSOperation, i am displaying huge data on UITableView.

but as i can see in XCode Instruments my memory usage continuously increasing

thats the reason, crashing activity is there in device not in simulator

Any one would like to comment on this ?


回答1:


Don't retrieve 10000 objects at once.

Use the NSAutoreleasePool and flush the pool at some consistent interval (interval to be determined via testing).

Every N iterations:

  1. save your context
  2. reset your context
  3. drain your pool

This will keep your memory usage down during import.




回答2:


Simulator has practically unlimited memory as it uses Mac's memory thus can even swap to hard drive. iDevice has on the other side very limited memory.

From your description it's not clear what you are doing wrong. It's up to you to analyse it, with Instruments you are already on a good way. Use Instruments's "Heapshot analysis" to find where your application is leaking memory. Recently bbum wrote a nice article about how to use it : http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/ . There's also a nice video from WWDC by Apple's engineers about using Instruments worth watching : http://developer.apple.com/videos/wwdc/2010/



来源:https://stackoverflow.com/questions/4131356/crashing-issue-due-to-memory-management-using-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!