title: Weak property not being set to nil
body: <p>I have the following properties defined on a UIViewController:</p>
  
  <pre><code>@property (nonatomic, strong) UIButton *strongButton;
  @property (nonatomic, weak) UIButton *weakButton;
  </code></pre>
  
  <p>These properties are not set via Interface Builder (i.e. they will always remain nil as long as I don't set them explicitly in code).</p>
  
  <p>I also added a category on UIButton to know exactly when it is dealloced:</p>
  
  <pre><code>@implementation UIButton (test)
  - (void)dealloc { NSLog(@"Dealloc called."); }
  @end
  </code></pre>
  
  <p>I have the following code in the <code>viewDidLoad</code> of the UIViewController:</p>
  
  <pre><code>self.strongButton = [[UIButton alloc] init];
  self.weakButton = self.strongButton;
  NSAssert(self.weakButton != nil, @"A: Weak button should not be nil.");
  NSLog(@"Setting to nil");
  self.strongButton = nil;
  NSLog(@"Done setting to nil");
  NSAssert(self.weakButton == nil, @"B: Weak button should be nil.");
  </code></pre>
  
  <p>When I run that code, it <strong>fails on the second assertion (B)</strong>. The log shows:</p>
  
  <ul>
  <li>Setting to nil</li>
  <li>Done setting to nil</li>
  <li><em>*</em> Assertion failure in -[ViewController viewDidLoad]</li>
  <li><em>*</em> Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'B: Weak button should be nil.'</li>
  </ul>
  
  <p>However, when I comment out the first assertion:</p>
  
  <pre><code>self.strongButton = [[UIButton alloc] init];
  self.weakButton = self.strongButton;
  //NSAssert(self.weakButton != nil, @"A: Weak button should not be nil.");
  NSLog(@"Setting to nil");
  self.strongButton = nil;
  NSLog(@"Done setting to nil");
  NSAssert(self.weakButton == nil, @"B: Weak button should be nil.");
  </code></pre>
  
  <p>The code runs fine with this in the log:</p>
  
  <ul>
  <li>Setting to nil</li>
  <li>Dealloc called.</li>
  <li>Done setting to nil</li>
  </ul>
  
  <p>Notice how the dealloc is not being called at the proper time in the first scenario.</p>
  
  <p>Why is that first NSAssert causing this weird behavior? Is this a bug or am I doing something wrong?</p>
  
  <p>(I am on iOS 6.1)</p>