Autorelease iPhone

前端 未结 6 548
遥遥无期
遥遥无期 2021-02-02 04:29

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 fairl

6条回答
  •  隐瞒了意图╮
    2021-02-02 05:20

    More important than the autorelease or manual-release choice is how often you alloc and dealloc your NSAutoreleasePools. Since most of the Cocoa frameworks use autorelease liberally, you need to have a proper pool draining strategy. Once that is in place, the choice of whether to release or autorelease becomes much less an issue.

    That being said, the only areas you should worry about are tight loops--allocate and release an NSAutoreleasePool every few iterations for best results; and when you have spawned another NSThread that doesn't have a Runloop--create a pool and drain it every so often becomes idle. Since most applications only allocate a small amount of data per event, UIKit's strategy of allocating the pool before the event is dispatched and releasing it after the dispatch returns works very well.

提交回复
热议问题