我使用自动参考计数 - ARC。我尝试在后台执行保存以避免中断UI。我试图使用@autoreleasepool构造函数,但我可能错了...那么应如何修改此代码以避免下面的错误?感谢。
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");
}
答案 0 :(得分:5)
将save方法包装在autoreleasePool块中:
-(void)save {
@autoreleasepool {
[wrapper setObject:currentVersion forKey:@"version"];
if (taskStore!=nil) [wrapper setObject:taskStore forKey:@"taskStore"];
[NSKeyedArchiver archiveRootObject:wrapper toFile:[self dataFilePathNew]];
NSLog(@"saved");
}
}