KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've already filed a radar (rdar://12311693, http://openradar.appspot.com/12311693 ) for the following issue, but I thought I'd post here as well to see if anyone can spot a mistake in my code that could lead to the crash. The following code sample leads to a crash due to an over-release when built with compiler optimization turned on (-Os), but does not crash when compiler optimization is turned off (-O0). The project is being built with Xcode 4.4.1 (4F1003), Apple LLVM compiler 4.0 The app crashes when num2 is over-released. Enable Zombie Objects to confirm that this is the case. // This crashes under -Os, but not under -O0 NSNumber *num1 = @((float)arc4random() / (float)UINT32_MAX); NSNumber *num2 = @((float)arc4random() / (float)UINT32_MAX); NSNumber *foo1 = num1; NSNumber *foo2 = num2; for (NSUInteger i=0; i<2; i++) { NSLog(@"foo1: %p %@", foo1, foo1); NSLog(@"foo2: %p %@", foo2, foo2); // swap foo1 and foo2 foo1 = num2; foo2 = num1; }
Tags (comma-separated)
Save Edits
Cancel