【发布时间】:2015-08-09 17:23:18
【问题描述】:
Instruments 显示了由于简单地打开和关闭警报控制器而导致的内存泄漏。
@IBAction func delBtnAc(sender: AnyObject) {
let deleteAlert = UIAlertController(title: "Delete Image?", message: "", preferredStyle: .Alert)
let cancelIt = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
deleteAlert.addAction(cancelIt)
presentViewController(deleteAlert, animated: true, completion: nil)
}
我已将警报减少为仅用于测试的取消按钮。
已编辑:在关闭时删除了 deleteAlert.dismissViewController。修复了保留周期,但仍显示内存泄漏。也许是一个错误。
【问题讨论】:
-
您不需要在您的操作中关闭警报控制器。它会自行消失...
-
我只是为了阻止内存泄漏。它看起来像一个创可贴。内存泄漏是错误吗?
-
正如您从我发布的答案中看到的那样,这实际上是造成内存泄漏
标签: ios swift memory-leaks uialertcontroller