iOS4 (UIAlertView) 为什么这段代码会导致内存泄漏? [英] iOS4 (UIAlertView) why this code causes memory leaks?
问题描述
假设您从头开始创建一个新的 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.
有什么问题?在 iOS4 之前 UIAlertView 有问题吗?
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 :)
这篇关于iOS4 (UIAlertView) 为什么这段代码会导致内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!