title: core data memory foot print in iOS keeps growing
body: <p>I am trying to backup a Core Data SQLite database. This code successfully processes the running database and merges the WAL file. Unfortunately, everytime it runs I see a bump of about 3-5 MB in my memory footprint. This is causing issues after the program has run for a while. Can someone help me reclaim the memory? I thought setting everything to nil would dealloc all of the objects from RAM, but that doesn't seem to be it.</p>
  
  <pre><code>-(void) backupDatabaseWithThisTimeStamp: (int) timeStamp withCompletionBlock:(void (^)(void))completion {
      NSDate *backupDate = [NSDate date];
      NSError *error;
  
      [self.defaultPrivateQueueContext save:&amp;error];
      if (error) {
          NSLog(@"error -&gt; %@",error);
      }
      dispatch_async(self.backupQueue, ^{
          // Let's use the existing PSC
          NSPersistentStoreCoordinator *migrationPSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
  
          // Open the store
          id sourceStore = [migrationPSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[self persistentStoreURL] options:nil error:nil];
  
          if (!sourceStore) {
              NSLog(@" failed to add store");
              migrationPSC = nil;
          } else {
              NSLog(@" Successfully added store to migrate");
  
              NSError *error;
              NSLog(@" About to migrate the store...");
              id migrationSuccess = [migrationPSC migratePersistentStore:sourceStore toURL:[self backupStoreURLwithTimeStamp: timeStamp] options:[self localStoreOptions] withType:NSSQLiteStoreType error:&amp;error];
  
              if (migrationSuccess) {
                  NSLog(@"store successfully backed up");
                  // Now reset the backup preference
                  NSManagedObjectContext *tempContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
                  tempContext.persistentStoreCoordinator = migrationPSC;
                  tempContext.undoManager = nil;
  
                  // clip out data
                  [CDrawColorData purgeDataOlderThan:backupDate fromContext:tempContext];
  
                  migrationPSC = nil;
                  tempContext = nil;
              }
              else {
                  NSLog(@"Failed to backup store: %@, %@", error, error.userInfo);
                  migrationPSC = nil;
              }
          }
          migrationPSC = nil;
          dispatch_async(dispatch_get_main_queue(), ^{
              if (completion) {
                  completion();
              }
          });
      });
  }
  
  self.backupQueue = _backupQueue = dispatch_queue_create("backup.queue", DISPATCH_QUEUE_SERIAL);
  
  localStoreOptions =
  - (NSDictionary*)localStoreOptions {
      return @{NSMigratePersistentStoresAutomaticallyOption:@YES,
           NSInferMappingModelAutomaticallyOption:@YES,
           NSSQLitePragmasOption:@{ @"journal_mode" : @"DELETE" }};
  }
  </code></pre>
  
  <p>commenting out everything that happens after the migrationSuccess point does not effect the memory footprint.</p>