CoreData release memory in private moc

I’m using Zarra’s way of importing large dataset into CoreData, by using 3 contexts, one is private. (the last one).

However the import uses and retains large amount of memory.
I tried to add an autoreleasepool in the process, but it’s not sorting effects.

How can I modify this code to save memory during or at the end of the process?
Should I also [temporaryContext reset] or refresh (faulting) objects at some point?

Thanks for any input, simplified controller code follows:

// import routine
    NSManagedObjectContext *temporaryContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    temporaryContext.parentContext = self.managedObjectContext;
    temporaryContext.undoManager = nil;

    [temporaryContext performBlock:^{
      @autoreleasepool {
        // Perform operations, create, update, delete and finally save.
        [temporaryContext save:nil];

      [self.managedObjectContext performBlock:^{
        [self.managedObjectContext save:nil];
        [self.privateWriterContext performBlock:^{
          [self.privateWriterContext save:nil];
          self->refreshInProgress = NO;
          dispatch_async(dispatch_get_main_queue(), ^{
            [self.refreshControl endRefreshing];

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>