Leaks with UIAlertController

落爺英雄遲暮 提交于 2019-11-29 16:46:00

问题


I added UIAlertController in my app by creating a category on UIViewController with the following method:

- (void)showAlertViewWithTitle:(NSString *)title
                       message:(NSString *)message
                       actions:(NSArray *)alertActions
{
   UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? : @"" message:message preferredStyle:UIAlertControllerStyleAlert];

   if (alertActions.count) {
      for (UIAlertAction *action in alertActions) {
         [alertController addAction:action];
      }
   } else {
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
      [alertController addAction:action];
   }

   [self presentViewController:alertController animated:YES completion:nil];
}

At first, everything looks great but when I analyze leaks with Instruments, each time I call this method, some leaks appear:

Here is how the call of showAlertViewWithTitle:message:actions: is done

[self showAlertViewWithTitle:nil message:@"Test message" actions:nil];

Any idea why I get all these leaks?

-- EDIT --

I tried the following in a sample project:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message"
                                                   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];

and I get the same leaks. I'm really not sure what's going on...


回答1:


This is an iOS bug.

This is also a duplicate of SO question iOS 8 Only Memory Leak with UIAlertController or UIActionSheet posted 1 day earlier.

See Apple Bug Reporter issue 21005708, Memory leak in UIAlertController under ARC.




回答2:


The leak seems to be fixed with iOS 8.2 and Xcode 6.2



来源:https://stackoverflow.com/questions/26273175/leaks-with-uialertcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!