performSelectorInBackground给出“没有池的自动释放".错误 [英] performSelectorInBackground gives "autoreleased with no pool in place" error
本文介绍了performSelectorInBackground给出“没有池的自动释放".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用自动引用计数-ARC.我尝试在后台执行保存,以避免打扰用户界面.我尝试使用@autoreleasepool构造函数,但可能将其放置在错误的位置上...那么应如何修改此代码,以避免出现以下错误?谢谢.
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");
}
推荐答案
您将保存方法包装在autoreleasePool块中:
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");
}
}
这篇关于performSelectorInBackground给出“没有池的自动释放".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文