iOS 8 Only Memory Leak with UIAlertController or UIActionSheet
Asked Answered
G

4

9

I'm seeing a memory leak in iOS 8 in simulator when I do the following with UIActionSheet or UIAlertController. UIActionSheet uses UIAlertController in IOS 8 so the issues are related.

showCameraAction gets called when a button is pressed. I've removed all of the content from the delegate method and still get the leak in the case shown below. Am I using UIActionSheet in some way that I shouldn't? I would appreciate any help in resolving this issue. The same code has no leaks with IOS 7 (in the simulator).

-(IBAction)showCameraAction:(id)sender
{

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Photo From:"
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:@"Phone", @"Flickr", nil];

[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
//also tried  just showInView: self.view
}

//empty

 - (void)actionSheet:(UIActionSheet *)actionSheet
 clickedButtonAtIndex:(NSInteger)buttonIndex {
 }

Also tried with UIAlertController, with the same result:

UIAlertController *alertController = [UIAlertController
                                      alertControllerWithTitle:@"Photo From:"
                                      message:@""
                                      preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *phoneAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Phone", @"Phone action")
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction *action)
                               {
                                   NSLog(@"Phone action");
                               }];

UIAlertAction *flickrAction = [UIAlertAction
                           actionWithTitle:NSLocalizedString(@"Flickr", @"Flickr action")
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action)
                           {
                               NSLog(@"Flickr action");
                           }];

[alertController addAction:phoneAction];
[alertController addAction:flickrAction];


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

Leaks tool screenshot

Screenshot with trace: https://www.dropbox.com/l/FmnTCd0PvVhuu16BVHZo7p

Gingery answered 8/10, 2014 at 0:4 Comment(6)
I get a similar leak with UIAlertController and UIAlertView: #26273675Tampere
#26278114Spellbound
@Jageen yes. I'm using ARC.Gingery
@Tampere Thanks. That's interesting. It looks like my UIActionSheet is using UIAlertController in the background in iOS 8 too, so they seem related.Gingery
I have run into this problem too! It leaks on the real iPad, and simulator only on iOS8.x See my message in the Apple forums devforums.apple.com/message/1099436#1099436Known
If you've got a reproducible bug in iOS then please report it to Apple: bugreport.apple.comAmmonal
A
5

I would suggest to use "UIAlertController" in iOS8. And dismiss the alertController object from the presented controller, while firing any event by "UIAlertAction" block.

UIAlertController  *alertController = [UIAlertController alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction  *alertAction = [UIAlertAction actionWithTitle:@"actionTitle"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Do ur stuff
[alertController dismissViewControllerAnimated:YES
                                    completion:NULL];
}];
[alertController addAction:alertAction];
[self presentViewController:alertController
                       animated:YES
                     completion:NULL];
Appendicectomy answered 13/7, 2015 at 12:22 Comment(0)
K
4

This is an iOS bug.

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

Kragh answered 18/5, 2015 at 21:15 Comment(0)
K
1

This is no answer, but more evidence for the leak, that exceeds a comment. May it help to find a solution or workaround. The leak seems to be device specific on iPad 3/Retina!

I have made some tests myself by overriding retain and release of the view-controller to show the leak in iOS 8.x

See also: https://devforums.apple.com/message/1099577#1099577

  • LEAKY Devices: iPad 3 (A1416), iPad Air Simulator
  • GOOD Devices: iPhone 6 iOS 8.1.3, iPhone 4s with iOS 8.1.2

AGC is the view-controller. The correct retain count should be 2.

iPad Retina Simulator iOS 8.1 AND real iPad LEAK // second run ... this time with LEAK by selecting an option 12:56:50.929 SimplySolitaire[27643:473670] >>> WILL actionSheet showInView: retain = 2 12:56:50.930 SimplySolitaire[27643:473670] AGC retain == 3 12:56:50.950 SimplySolitaire[27643:473670] AGC retain == 4 12:56:50.951 SimplySolitaire[27643:473670] AGC retain == 5 12:56:50.951 SimplySolitaire[27643:473670] AGC retain == 6 12:56:50.951 SimplySolitaire[27643:473670] <<< DID actionSheet showInView: retain = 6 12:56:50.998 SimplySolitaire[27643:473670] AGC release = 5 12:56:51.042 SimplySolitaire[27643:473670] AGC release = 4 12:56:51.042 SimplySolitaire[27643:473670] AGC release = 3 // USER dismisses the action sheet with tapping a button (delegate is nil) 12:56:53.257 SimplySolitaire[27643:473670] AGC retain == 4 12:56:53.257 SimplySolitaire[27643:473670] AGC retain == 5 12:56:53.258 SimplySolitaire[27643:473670] AGC retain == 6 12:56:53.258 SimplySolitaire[27643:473670] AGC retain == 7 12:56:53.258 SimplySolitaire[27643:473670] AGC release = 6 12:56:53.259 SimplySolitaire[27643:473670] AGC release = 5 12:56:53.612 SimplySolitaire[27643:473670] AGC release = 4 12:56:53.612 SimplySolitaire[27643:473670] AGC release = 3 // <<<<<<<<<< LEAK should be 2 // the last release is missing, but only iOS system code has executed.

iPad Retina Simulator iOS 8.1 AND real iPad, dismiss without LEAK 12:54:54.757 SimplySolitaire[27643:473670] >>> WILL actionSheet showInView: retain = 2 12:54:54.758 SimplySolitaire[27643:473670] AGC retain == 3 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 4 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 5 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 6 12:54:54.798 SimplySolitaire[27643:473670] <<< DID actionSheet showInView: retain = 6 12:54:54.845 SimplySolitaire[27643:473670] AGC release = 5 12:54:54.891 SimplySolitaire[27643:473670] AGC release = 4 12:54:54.891 SimplySolitaire[27643:473670] AGC release = 3 // NOW ... dismiss the action sheet without selection (delegate is nil) 12:55:05.643 SimplySolitaire[27643:473670] AGC retain == 4 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 5 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 6 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 7 12:55:05.645 SimplySolitaire[27643:473670] AGC release = 6 12:55:05.645 SimplySolitaire[27643:473670] AGC release = 5 12:55:05.996 SimplySolitaire[27643:473670] AGC release = 4 12:55:05.997 SimplySolitaire[27643:473670] AGC release = 3 12:55:05.997 SimplySolitaire[27643:473670] AGC release = 2 // this is a correct retain of 2

Known answered 5/2, 2015 at 12:52 Comment(0)
A
-1

I would suggest switching to UIAlertController. UIActionSheet is deprecated in iOS 8, so you might try giving it a shot and see if there's still the leak

Archaeology answered 8/10, 2014 at 0:24 Comment(3)
Thanks! I was not aware of that, and xCode didn't warn me either. However, it appears that UIAlertController is showing the same issue per this: #26273675Gingery
Confirmed that use of UIAlertController shows the same memory leak.Gingery
Did you ever resolve this problem Praneeth? Just wondering if it was another factor, (which is why it still happened after you switched to UIAlertController)Thanksgiving

© 2022 - 2024 — McMap. All rights reserved.