views:

182

answers:

1

I'm using Core Data to store lists of data. So, there's parent objects with any number of child objects. Core Data does a great job keeping my memory use low while I'm inserting objects and reading but when I do a delete operation the memory spikes way up.

When I delete a parent object with ~5000 children the cascade delete uses ~10MB. This scales linearly so one with 10,000 uses 20MB. As near as I can tell, it's reading into memory the entire object graph before it does the delete. I'm guessing this is to ensure data integrity and validity but I really need it to use less memory.

Does anyone know how to get Core Data to use less memory on cascade deletes? Or do I have to do the cascade manually to decrease the memory usages?

A: 

For now you’ll have to manually cascade if you want to reduce the high-water mark. Two points:

  1. You should file a bug with Apple requesting more control over the faulting behavior when cascade-deleting.
  2. Have you verified that this temporary growth in memory is actually causing trouble for your application? It’s certainly worthwhile to try to reduce your memory usage, but making this delete manual may mean you lose out on performance enhancements in future updates unless you change your code again.
Ben Stiglitz
I missed that this was posted in “iphone”—presumably you’re worried about being evicted for memory growth.
Ben Stiglitz