自动释放iPhone [英] Autorelease iPhone

查看:167
本文介绍了自动释放iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发一个iPhone应用程序的结束,我想知道在开发iphone时使用autorelease是多么糟糕。我面临一些相当随机的崩溃,到目前为止,我不能确定其他任何东西,除了内存使用。

Coming up towards the end of developing an iPhone application and I'm wondering just how bad is it to use autorelease when developing for the iphone. I'm faced with some fairly random crashes and, so far, I can't pinpoint it to anything other than sloppy memory usage.

作为一个可可新手,我记得最初阅读一个指南文档,强烈建议避免自动释放,有利于手动保留/释放iPhone。然而,一个更高级的可可开发商早就来了(谁讽刺地已经放开了),谁使用autorelease在整个地方。不可否认,我进了猴子看猴子做模式,它似乎回来困扰我(我现在是项目中唯一的开发人员)。

As a Cocoa newbie I remember initially reading a guideline document that strongly suggested avoiding autorelease in favor of manual retain/release for iPhone. However, a more 'senior' Cocoa developer came on board early on (who ironically has been let go since), who used autorelease all over the place. Admittedly, I was went into "monkey see monkey do" mode, and it appears to be coming back to haunt me (I'm now the only developer on the project).

那么接下来该怎么做呢?在我看来,我必须分支代码,并尝试通过和替换,在可能的情况下,自动释放代码保持我的手指交叉,我不会无意中打破了应用程序。看起来很多库调用导致autoreleased对象像stringWithFormat和几乎任何东西,我不使用alloc自己。任何其他的问题和/或建议,我应该寻找?感谢Cocoa gurus。

So what to do next? It seems to me that I have to branch the code and try to go through and replace, where possible, autorelease code keeping my fingers crossed that I don't inadvertently break the app. It seems a lot of library calls result in autoreleased objects like stringWithFormat and pretty much anything where I'm not using alloc myself. Any other gotchyas and/or suggestions I should be looking out for? Thanks Cocoa gurus.

推荐答案

使用release而不是autorelease可以改善内存使用,但是如果你不遵循保留/释放规则,它不会帮助崩溃。我会阅读一些关于Obj-C内存管理的教程,如果你对你应该做什么有点朦胧,然后使用调试器和崩溃报告去找出你在哪里释放对象。 是开始的两个好地方。

Using release instead of autorelease can improve memory usage in tight spots (which is good on the iPhone), but it's not going to help at all with crashing if you're not following the retain / release rules. I would read a few tutorials on memory management in Obj-C if you're still a little hazy on what you should be doing, and then go after those crashes using the debugger and crash reports to find out where you're over releasing objects. This and this are two good places to start.

这篇关于自动释放iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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