iOS4(UIAlertView)为什么这段代码会导致内存泄漏?
假设您从头开始创建一个新的 iOS 应用程序,只有一个窗口。 然后将此代码放入 appDelegate 应用程序 didFinishLaunching 方法中:
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 中,完全没有问题。
当然,在真实的应用程序中,UIalertView 是由按钮触发的,但结果是相同的。
问题是什么 ? UIAlertView 在 iOS4 之前还有 bug 吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在模拟器中检查泄漏。它没有相同的内存模型,因此在没有内存模型时会报告泄漏。
在真实设备上进行测试,如果泄漏仍然存在,请将其作为错误报告给 Apple :)
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 :)