Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Created February 13, 2013 22:06
Show Gist options
  • Save bjhomer/4948803 to your computer and use it in GitHub Desktop.
Save bjhomer/4948803 to your computer and use it in GitHub Desktop.
Here's a hang inside the runtime. rdar://13210148
//
// AppDelegate.m
// RuntimeHang
//
// Created by BJ Homer on 2/13/13.
// Copyright (c) 2013 BJ Homer. All rights reserved.
//
#import "AppDelegate.h"
// ----------------- CKObject Implementation ---------------- //
@interface CKObject : NSObject
@end
@implementation CKObject
+ (void)initialize {
[super initialize];
NSString *str = [[NSString alloc] initWithFormat:@"%s", __PRETTY_FUNCTION__];
#pragma unused (str)
// When this string is deallocated, if we are inside a call to objc_storeWeak(), we will hang
}
@end
// ----------------- AppDelegate Implementation ---------------- //
@interface AppDelegate ()
@property (weak) CKObject *someObject; // Important; this MUST be a weak property
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// This code will hang inside +[CKObject initialize]. It happens when an NSKVONotifying_CKObject is assigned to a weak property.
// The bug only happens on iOS devices (tested with iOS 6.1.1). It does not happen in the 6.1 simulator shipped with Xcode 4.6 release.
CKObject *obj = [CKObject new];
[obj addObserver:self forKeyPath:@"foo" options:0 context:0];
NSLog(@"Starting the test. If the bug still exists, you will see no logging after this point.");
self.someObject = obj;
NSLog(@"If you see this, the bug is fixed.");
[obj removeObserver:self forKeyPath:@"foo"];
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment