内存泄漏在Swift中使用UIAlertController

我提出了一个简单的UIViewController使用这个简单的代码

@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) } 

当我按下我的界面上的button,我把这个IBAction和UIAlertController出现。 但是当我点击取消buttonclosures控制器泄漏工具发现泄漏,你可以在这个图像中看到:

在这里输入图像说明

我已经尝试把这样的封闭处理参数:

 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 })) 

但总是有泄漏。

UIViewController有很多陷阱。

Ash Furrow解决了这篇博客中的许多内存问题。 他尝试了弱自我的东西,但决定使用一个局部variables,然后在closures中使用。