iOS4 (UIAlertView) why this code causes memory lea

2019-01-27 06:37发布

问题:

suppose you create a new iOS app from scratch, with just one single window. then you put this code in the appDelegate application didFinishLaunching method :

UIAlertView *myAlert = [[UIAlertView alloc] 
  initWithTitle:@"alert"                                   
  message:@"message"
  delegate:nil /* same problem with 'delegate:self' */
  cancelButtonTitle:nil 
  otherButtonTitles:@"Ok", nil];
[myAlert show];
[myAlert release];

build and run in simulator 4.1, attach instrument, and... this causes each time a memory leak. in simulator 3.1.2 on leopard, no problem at all.

Of course, in a real app, the UIalertView is trigerred by a button, but the result is identical.

What is the problem ? is UIAlertView buggy until iOS4 ?

回答1:

Don't check for leaks in a simulator. It doesn't have the same memory model so reports leaks when there aren't any.

Test on a real device and if the leak is still there, report it as a bug to Apple :)