为什么自动释放特别危险/昂贵的iPhone应用程序? [英] Why is autorelease especially dangerous/expensive for iPhone applications?

查看:127
本文介绍了为什么自动释放特别危险/昂贵的iPhone应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个主要来源(或一个非常好的解释)来支持在编写软件时使用 autorelease 是危险或过于昂贵的说法iPhone。

I'm looking for a primary source (or a really good explanation) to back up the claim that the use of autorelease is dangerous or overly expensive when writing software for the iPhone.

一些开发人员提出这个说法,我甚至听说Apple不推荐它,但我还是没有能够找到任何具体的资源来支持它了。

Several developers make this claim, and I have even heard that Apple does not recommend it, but I have not been able to turn up any concrete sources to back it up.

SO参考:

autorelease-iphone

为什么会造成内存泄漏(iPhone)?

注意:从概念的角度来看,我可以看到 autorelease 比对发布的简单调用稍贵,但我不认为小额罚款足以让Apple推荐反对它。

Note: I can see, from a conceptual point of view, that autorelease is slightly more expensive than a simple call to release, but I don't think that small penalty is enough to make Apple recommend against it.

真实的故事是什么?

推荐答案

(不能接受你自己的答案?)

(cannot accept your own answer?)

嗯,毕竟,我确实设法找到了来自Apple Developer的参考,在页面底部附近作为附注添加:

Well, after all that, I did manage to find a reference from Apple Developer, added as a side-note near the bottom of the page:


iPhone OS注意:因为在iPhone OS $ b上$ b一个应用程序在一个更加
内存受限的环境中执行,
使用自动释放池是
不鼓励在
代码的方法或块中(例如,循环)
应用程序创建了许多对象。
相反,你应该尽可能明确地释放
对象。

iPhone OS Note: Because on iPhone OS an application executes in a more memory-constrained environment, the use of autorelease pools is discouraged in methods or blocks of code (for example, loops) where an application creates many objects. Instead, you should explicitly release objects whenever possible.

但是,这建议谨慎使用autorelease,而不是完全避免它。

Still, this suggests using autorelease carefully, not avoiding it altogether.

(现在我的评论)

听起来有一定数量的维护池的开销。我阅读了这篇文章尽量避免自动释放,因为我更喜欢事物保持一致。如果你在自动释放下有一些内存,而其他内存完全是手动管理的,那可能会有点混乱。

It sounds like there is a certain amount of overhead in maintaining the pool. I read this article which would lead me to probably avoid autorelease as much as possible because I prefer things to be consistent. If you have some memory under autorelease and other memory being totally manually managed it can be a bit more confusing.

这篇关于为什么自动释放特别危险/昂贵的iPhone应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆