Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaks with UIAlertController

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:

enter image description here

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...

like image 650
MartinMoizard Avatar asked Oct 09 '14 07:10

MartinMoizard


1 Answers

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.

like image 139
SwiftArchitect Avatar answered Nov 16 '22 10:11

SwiftArchitect