Core Data performance deleteObject and save managed object context

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-05-04T16:56:16Z Indexed on 2010/05/04 16:58 UTC
Read the original article Hit count: 608

I am trying to figure out the best way to bulk delete objects inside of my Core Data database.

I have some objects with a parent/child relationship. At times I need to "refresh" the parent object by clearing out all of the existing children objects and adding new ones to Core Data. The 'delete all' portion of this operation is where I am running into trouble. I accomplish this by looping through the children and calling deleteObject for each one.

I have noticed that after the NSManagedObjectContext:Save call following all of the deleteObject calls is very slow when I am deleting 15,000 objects.

How can I speed up this call? Are there things happening during the save operation that I can be aware of and avoid by setting parameters different or setting up my model another way? I've noticed that memory spikes during this operation as well. I really just want to "delete * from".

Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about coredata