title: Prevent ARC from deallocating something that's not currently being used but will be soon?
body: <p>I've run into this problem a couple of times and want to know the correct approach to take.</p>
  
  <p>For an example, let's say I'm writing an iPhone app and I want a custom alert view class that uses blocks.</p>
  
  <p>So I write the class, then later on in my code I go:</p>
  
  <pre><code>MyAlertView *alert = [MyAlertView alertWithBlahBlahBlah...];
  [alert addButton:@"button" withBlock:^{ ... }];
  [alert show];
  </code></pre>
  
  <p>Somewhere in the alert view class, we have</p>
  
  <pre><code>- (void)addButton:(NSString *)button withBlock:(void (^))block {
      [_blocks setObject:[block copy] forKey:button];
  }
  
  - (void)show {
      ... drawing stuff ...
      UIButton *button = ...
      [button addTarget:self selector:@selector(buttonPressed:) ...];
      ...
  }
  
  - (void)buttonPressed:(id)sender {
      ((void (^)())[_blocks objectForKey:[sender title]])();
  }
  </code></pre>
  
  <p>So, the alert view now shows up just fine. The problem is, if I tap a button, it attempts to send the <code>buttonPressed:</code> selector to the <code>MyAlertView</code> object that was displayed. The <code>MyAlertView</code> has, however, been removed from the superview at this time. ARC decides that because the alert view is not owned by anyone anymore, it should be deallocated, not knowing that a button needs to message it in the future. This causes a crash when the button is tapped.</p>
  
  <p>What's the right way to keep the alert view in memory? I could make the <code>MyAlertView</code> object a property of the class that's using it, but that's kind of silly (what if I want to show two alerts at once?).</p>