Can I clear the Managed Object Context?

前端 未结 1 1605
心在旅途
心在旅途 2021-01-31 12:21

Problem: I am doing a really big import where I parse an XML file. For every 10 parsed managed objects, I want to save the Managed Object Context and get rid of those 10 objects

相关标签:
1条回答
  • 2021-01-31 12:51

    In a situation like this there are four things to remember to do:

    1. Wrap your loop in a NSAutoreleasePool
    2. Periodically save the context; then
    3. Reset the context with -reset
    4. Release and re-create the autorelease pool

    This will flush all of the memory being used and clear the context.

    0 讨论(0)
提交回复
热议问题