iOS8下,UIAlertController内存泄露怎么办?

来源:互联网 发布:移动网络电视首页 编辑:程序博客网 时间:2024/06/06 20:26

用Xcode 6.4调用Instruments查看内存泄露时,发现UIAlertController内存泄露了。

代码如下:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""                                                                             message:@""                                                                      preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleCancel handler:nil];UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDestructive         handler:^(UIAlertAction *action) {        //do someThing    }];[alertController addAction:cancelAction];[alertController addAction:deleteAction];[self presentViewController:alertController animated:YES completion:nil];

怎么才能使内存不泄露呢?
可以把UIAlertController *alertController改为成员变量,即:

@property (strong, nonatomic) UIAlertController *alertController;

这样就不会造成内存泄露了。

0 0
原创粉丝点击