1
我我的程序的执行过程中收到一个警告在Xcode:当应用程序提供了一个NSOpenPanel选择将异步加载某些文件时出现NSOpenPanel和检测到泄漏观察员
2016-01-21 03:19:26.468 IsoMetadonnees[1975:303] An instance 0x1004eefd0 of class NSVBOpenPanel was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x608000444710> (
<NSKeyValueObservance 0x6080000d5310: Observer: 0x100592cf0, Key path: level, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x6080004486a0>
)
的问题。该应用程序不会崩溃和文件正确加载...
我不创建任何值观察员,所以我想象观察者是由NSOpenPanel创建的,但我不知道任何过程,以移除观察者,我还没有创建...
尽管有这个警告,我做了多个负载,没有通知任何崩溃。我使用我的应用程序多年以来没有任何问题,但我最近改用ARC;可能是此时出现(或被检测到)的问题。
这里是我的代码的简化版本:前
- (IBAction)ajoutFichier:(id)sender {
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
// Here some configurations of openPanel
if ([openPanel runModal] == NSOKButton) {
tmp_listeURLFichiers = [openPanel URLs];
}
//[openPanel close]; // I add this code unsuccessfully
openPanel = nil; // I add this code unsuccessfully
// I call a task in back ground to load my files
if ((tmp_listeURLFichiers != nil) && ([tmp_listeURLFichiers count]>0))
[self performSelectorInBackground:@selector(ajouteListeFichiers:) withObject:tmp_listeURLFichiers];
}
// Load files in background
-(BOOL) ajouteListeFichiers:(NSArray *)listeDesFichierAAjouter {
@autoreleasepool {
// Some stuff to show a progress bar
// Loop to load selected files
for (id tmpCheminVersMonImage in listeDesFichierAAjouter) {
// Load files
}
} // <========== THE WARNING OCCURS AT THIS POINT, WHEN autoreleasepool is cleaned
return (YES);
}
我尝试添加
[openPanel close];
和
openPanel = nil;
强制从内存中释放openPanel(因而观察者)开始后台任务,但这并没有改变任何东西...
你有什么想法吗?
谢谢你的帮助!
什么是'NSVBOpenPanel'?你是否添加了观察者?你有没有在NSKVODeallocateBreak上设置一个断点,然后给观察者设置断点? – Willeke
我不知道NSVBOpenPanel是什么...我只使用NSOpenPanel。我想我们使用沙箱时,NSVBOpenPanel是一种NSOpenPanel。 我按照警告告诉我要做的方式设置了一个断点,并且我可以确定警告发生在我的第一篇文章中的autorelease池(我在代码中指出的点)处。 我没有添加任何观察者... – brolive