Created
February 11, 2012 13:11
-
-
Save joerick/1799355 to your computer and use it in GitHub Desktop.
KVO/KVC crash on reloading unloaded bundles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////// SIAppDelegate.h //////////////////////////// | |
#import <Cocoa/Cocoa.h> | |
@interface SIAppDelegate : NSObject <NSApplicationDelegate> | |
@property (assign) IBOutlet NSWindow *window; | |
@end | |
//////////////////////// SIAppDelegate.m //////////////////////////// | |
#import "SIAppDelegate.h" | |
#import "Bundle.h" | |
@implementation SIAppDelegate | |
@synthesize window; | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"testbundle" ofType:@"bundle"]; | |
NSBundle *bundle = [NSBundle bundleWithPath: bundlePath]; | |
for (int i = 0; i < 100; i++) | |
{ | |
[bundle load]; | |
Class bundleClass = [bundle principalClass]; | |
[[[bundleClass alloc] init] release]; | |
[bundle unload]; | |
} | |
} | |
@end | |
//////////////////////// Bundle.h //////////////////////////// | |
#import <Foundation/Foundation.h> | |
@interface Bundle : NSObject | |
@property (retain) NSString *name; | |
@end | |
//////////////////////// Bundle.m //////////////////////////// | |
#import "Bundle.h" | |
@implementation Bundle | |
@synthesize name; | |
- (id)init | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
[self addObserver: self | |
forKeyPath: @"name" | |
options: 0 | |
context: nil]; | |
self.name = @"jim"; | |
} | |
return self; | |
} | |
- (void)observeValueForKeyPath:(NSString *)keyPath | |
ofObject:(id)object | |
change:(NSDictionary *)change | |
context:(void *)context | |
{ | |
NSLog(@"observer fired"); | |
} | |
- (void)dealloc | |
{ | |
[self removeObserver: self | |
forKeyPath: @"name"]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment