Objective c NSOPEN面板并检测到泄漏的观察者

Objective c NSOPEN面板并检测到泄漏的观察者,objective-c,cocoa,nsopenpanel,Objective C,Cocoa,Nsopenpanel,在程序执行期间,我收到了来自XCode的警告: 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 mistaken

在程序执行期间,我收到了来自XCode的警告:

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>
  )

在开始后台任务之前,强制从内存中释放openPanel(以及观察者),但这不会改变任何事情

你知道吗


谢谢你的帮助

我可以使用以下技巧解决此问题:

我在视图控制器中声明一个变量:

__strong NSOpenPanel  *prgOpenPanel;
然后我在代码中使用它

//NSOpenPanel  *prgOpenPanel = [NSOpenPanel openPanel];
self.prgOpenPanel = nil;
self.prgOpenPanel = [NSOpenPanel openPanel];
// Here some configurations of openPanel

if ([prgOpenPanel runModal] == NSOKButton) {
    tmp_listeURLFichiers = [prgOpenPanel URLs];
    if ((tmp_listeURLFichiers != nil) && ([tmp_listeURLFichiers count]>0))
        [self performSelectorInBackground:@selector(ajouteListeFichiers:) withObject:tmp_listeURLFichiers];
}

没有更多的警告

我可以使用以下技巧解决此问题:

我在视图控制器中声明一个变量:

__strong NSOpenPanel  *prgOpenPanel;
然后我在代码中使用它

//NSOpenPanel  *prgOpenPanel = [NSOpenPanel openPanel];
self.prgOpenPanel = nil;
self.prgOpenPanel = [NSOpenPanel openPanel];
// Here some configurations of openPanel

if ([prgOpenPanel runModal] == NSOKButton) {
    tmp_listeURLFichiers = [prgOpenPanel URLs];
    if ((tmp_listeURLFichiers != nil) && ([tmp_listeURLFichiers count]>0))
        [self performSelectorInBackground:@selector(ajouteListeFichiers:) withObject:tmp_listeURLFichiers];
}

没有更多的警告

什么是
NSVBOpenPanel
?你添加了观察员吗?您是否在NSKVODeallocateBreak上设置了断点并向观察者发送po?我不知道NSVBOpenPanel是什么。。。我只使用NSOpenPanel。我猜当我们使用沙箱时,NSVBOpenPanel是一种NSOpenPanel。我按照警告告诉我的方式设置了一个断点,我可以在我的第一篇文章中确定警告发生在自动释放池的排水口(我在代码中指示的点)。我没有添加任何观察者…什么是
NSVBOpenPanel
?你添加了观察员吗?您是否在NSKVODeallocateBreak上设置了断点并向观察者发送po?我不知道NSVBOpenPanel是什么。。。我只使用NSOpenPanel。我猜当我们使用沙箱时,NSVBOpenPanel是一种NSOpenPanel。我按照警告告诉我的方式设置了一个断点,我可以在我的第一篇文章中确定警告发生在自动释放池的排水口(我在代码中指示的点)。我没有添加任何观察者。。。
//NSOpenPanel  *prgOpenPanel = [NSOpenPanel openPanel];
self.prgOpenPanel = nil;
self.prgOpenPanel = [NSOpenPanel openPanel];
// Here some configurations of openPanel

if ([prgOpenPanel runModal] == NSOKButton) {
    tmp_listeURLFichiers = [prgOpenPanel URLs];
    if ((tmp_listeURLFichiers != nil) && ([tmp_listeURLFichiers count]>0))
        [self performSelectorInBackground:@selector(ajouteListeFichiers:) withObject:tmp_listeURLFichiers];
}