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

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

reply all(2)
伊谢尔伦

The action time of the two is different. The writing method of AutoReleasePool object acts on the runtime, and @autoreleasepool acts on the compilation phase. If you want to enable ARC, you need to tell the compiler to enable automatic reference counting management during the compilation phase, and it cannot be added dynamically at runtime.

小葫芦

Now Apple recommends using @autoreleasepool{}, regardless of whether ARC is used

@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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!