objective-c - NSAutoreleasePool和autoreleasepool的区别
ringa_lee
ringa_lee 2017-04-21 11:16:28
0
2
368

NSAutoreleasePool的官方解释
Important If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks instead. For example, in place of:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init;
// Code benefitting from a local autorelease pool.
[pool release];

you would write:

@autoreleasepool {
// Code benefitting from a local autorelease pool.
}

@autoreleasepool blocks are more efficient than using an instance of NSAutoreleasePool directly; you can also use them even if you do not use ARC.

xcode4.3引入ARC,release这块就有些变化,当你使用ARC,就必须将NSAutoreleasePool的地方换成 @autoreleasepool

http://marshal.easymorse.com/archives...

ringa_lee
ringa_lee

ringa_lee

全部回覆(2)
伊谢尔伦

兩者的作用時間不一樣。 AutoReleasePool物件的寫法作用於執行時,@autoreleasepool作用於編譯階段。如果要啟用ARC的話,在編譯階段就需要告訴編譯器啟用自動引用計數管理,而不能在執行時動態新增。

小葫芦

現在蘋果推薦都使用@autoreleasepool{},無論是否使用ARC

@autoreleasepool blocks are more efficient than using an instance of > NSAutoreleasePool directly; you can also use them even if you do not use ARC http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!