KVO/KVC在重新加载以前卸载的bundle时崩溃



我遇到了可加载捆绑包和KVO的问题。似乎任何一个实例上附加了KVO观察器的类都无法通过NSBundle的-unload方法安全地卸载。

我正在做以下事情:

for (int i = 0; i < 100; i++)
{
    [bundle load];
    Class bundleClass = [bundle principalClass];
    [[[bundleClass alloc] init] release];
    [bundle unload];
}

在丛的原理类-init方法中,

    [self addObserver: self 
           forKeyPath: @"name"
              options: 0
              context: nil];
    self.name = @"jim";

循环经过多次迭代,有时在第二轮崩溃,有时在30轮崩溃。

它总是与EXC_BAD_ACCESS信号的回溯一起崩溃。

#0  0x00007fff8a30deab in objc_msgSend ()
#1  0x00007fff8609d862 in NSKeyValueNotifyObserver ()
#2  0x00007fff860be99b in NSKeyValueDidChange ()
#3  0x00007fff8606b0fb in -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] ()
#4  0x00000001007a4c2c in -[Bundle init] (self=0x101902130, _cmd=0x7fff8ea369b0) at /Users/joerick/Desktop/bundleTest/testbundle/Bundle.m:26
#5  0x0000000100001731 in -[SIAppDelegate applicationDidFinishLaunching:] (self=0x100326a90, _cmd=0x7fff876e285f, aNotification=0x100131ea0) at /Users/joerick/Desktop/bundleTest/bundleTest/SIAppDelegate.m:28
#6  0x00007fff8606ade2 in __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 ()
#7  0x00007fff8b470e0a in _CFXNotificationPost ()
#8  0x00007fff86057097 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#9  0x00007fff8e1bbaa7 in -[NSApplication _postDidFinishNotification] ()
#10 0x00007fff8e1bb80d in -[NSApplication _sendFinishLaunchingNotification] ()
....

此处为完整代码

您可以在此处下载显示此问题的示例项目。

我想这是Cocoa的一个bug,但我想知道是否有人能看到我在这里做了什么愚蠢的事情?

我已经向苹果公司报告了这一情况。

rdar://11017946

最新更新