title: What is the most efficient way to delete a large number (10.000+) objects in Core Data?
body: <p>The way I'm trying to delete multiple sets of 10.000+ NSManagedObjects is just too memory intensive (around 20MB live bytes), and my app is being jettisoned. Here is the implementation of the delete method: </p>
  
  <pre><code>+ (void)deleteRelatedEntitiesInManagedObjectContext:(NSManagedObjectContext *)context 
  {
      NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
      [context setUndoManager:nil];
  
      [fetch setEntity:[NSEntityDescription entityForName:NSStringFromClass(self) inManagedObjectContext:context]];
      [fetch setIncludesPropertyValues:NO];
  
      NSError *error = nil;
      NSArray *entities = [context executeFetchRequest:fetch error:&amp;error];
  
      NSInteger deletedCount = 0;
      for (NSManagedObject *item in entities) {
          [context deleteObject:item];
          deletedCount++;
  
          if (deletedCount == 500) {
              [context save:&amp;error];
              deletedCount = 0;
          }
      }
  
      if (deletedCount != 0) {
          [context save:&amp;error];
      }
  }
  </code></pre>
  
  <p>I've tried: -setFetchBatchSize, but there's even more memory used.</p>
  
  <p>What would be a more memory-efficient way to do this?</p>