2
我遇到了與可加載捆綁包和KVO有關的問題。似乎任何有KVO觀察者附加到它的實例的類都不能通過NSBundle的-unload
方法安全地卸載。KVO/KVC在重新加載之前卸載的捆綁包時崩潰
我做了以下內容:
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";
環路獲得通過迭代的次數,有時繞第二圈時崩潰有時候在三十號。
使用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]()
....
您可以下載顯示這個問題here一個樣本項目。
我在想這是可可中的一個錯誤,但我想知道是否有人能看到我是否在這裏做什麼愚蠢的事情?