views:

358

answers:

1

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 in memory, so that I have never more than 10 objects in memory at a time.

After saving it, how could I clear the context so that all the objects go away from memory?

+6  A: 

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.

Marcus S. Zarra
Hey Marcus!! Aren't you the guy who wrote that big Core Data book? Thanks for the answer. Pretty sure it's the best one ;)
dontWatchMyProfile
Yes, I wrote the book :)
Marcus S. Zarra