iOS4(UIAlertView)为什么这段代码导致内存泄漏?

问题描述:

假设您从头开始创建一个新的iOS应用程序,只需一个窗口。
然后你将这段代码放入appDelegate应用程序didFinishLaunching方法:

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];

在模拟器4.1中构建和运行,附加工具,并且...
这导致每个时间内存泄漏。在leopard上的模拟器3.1.2中
,完全没问题。

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.

当然,在一个真实的应用程序中,UIalertView被一个按钮驱动,但是结果是一样的。

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

有什么问题?
是UIAlertView越野车直到iOS4?

What is the problem ? is UIAlertView buggy until iOS4 ?

不要检查模拟器中的泄漏。它没有相同的内存模型,因此报告泄漏时没有。

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

在真实设备上进行测试,如果泄漏仍然存在,请将其报告为Apple的一个错误:)

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