1

I use Automatic Reference Counting - ARC. I try to perform saving in the background to avoid interrupting the UI. I tried to use the @autoreleasepool constructor, but I may be placing it wrong... So how should this code be modified to avoid the error below? Thanks.

2011-12-25 22:04:41.177 MakeMyDay[1106:5f5f] *** __NSAutoreleaseNoPool(): Object 0x102210 of class NSCFString autoreleased with no pool in place - just leaking


-(void)beginAutoSave {
    if (saveTimer==nil) {
        NSLog(@"Begin Autosave");
        saveTimer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(saveInBackground) userInfo:nil repeats:YES];                    
    }
}


-(void)saveInBackground {
        [self performSelectorInBackground:@selector(save) withObject:nil];
}

- (void)save
{    
    [wrapper setObject:currentVersion forKey:@"version"];
    if (taskStore!=nil) [wrapper setObject:taskStore forKey:@"taskStore"];
    [NSKeyedArchiver archiveRootObject:wrapper toFile:[self dataFilePathNew]];  
    NSLog(@"saved");
}
folium
  • 353
  • 1
  • 15

1 Answers1

5

You wrap your save method inside the autoreleasePool block:

-(void)save {

  @autoreleasepool {

    [wrapper setObject:currentVersion forKey:@"version"];
    if (taskStore!=nil) [wrapper setObject:taskStore forKey:@"taskStore"];
    [NSKeyedArchiver archiveRootObject:wrapper toFile:[self dataFilePathNew]];  
    NSLog(@"saved");

  }

}
Ecarrion
  • 4,940
  • 1
  • 33
  • 44