iOS4 (UIAlertView) why this code causes memory leaks?

最后都变了- 提交于 2019-11-28 06:54:14

问题


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 :)



来源:https://stackoverflow.com/questions/4303921/ios4-uialertview-why-this-code-causes-memory-leaks

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