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

发布于 2024-10-04 23:10:13 字数 562 浏览 0 评论 0原文

假设您从头开始创建一个新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

貪欢 2024-10-11 23:10:13

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

在真实设备上进行测试,如果泄漏仍然存在,请将其作为错误报告给 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文