title: Memory Leak using an UIAlertController in Swift
body: <p>I present a simple UIViewController using this simple code</p>
  
  <pre><code>@IBAction func addNewFeed(sender: UIBarButtonItem)
  {
  
      var alertView: UIAlertController? = UIAlertController(title: NSLocalizedString("New Feed", comment: "Titolo popup creazione feed"),
          message: NSLocalizedString("Insert the Title and the Link for the new Feed.", comment: "Messaggio creazione nuovo feed"),
          preferredStyle: UIAlertControllerStyle.Alert)
  
  
      alertView!.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Annulla popup creazione nuovo feed"),
          style: UIAlertActionStyle.Cancel,
          handler: nil))
  
      presentViewController(alertView!, animated: true, completion: nil)
  
  }
  </code></pre>
  
  <p>When i push a button on my interface i call this IBAction and UIAlertController appears. But when i click on Cancel button to dismiss the controller Leak Tool found a leak as you can see in this image:</p>
  
  <p><img src="https://i.stack.imgur.com/SegVd.png" alt="enter image description here"></p>
  
  <p>I have tried putting a closure like this in handler parameter:</p>
  
  <pre><code>alertView!.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Annulla popup creazione nuovo feed"),
          style: UIAlertActionStyle.Cancel,
          handler: {[weak self] action in self!.dismissViewControllerAnimated(true, completion: nil)
          alertView = nil
          }))
  </code></pre>
  
  <p>but there's always that leak.</p>