@autoreleasepool 代替 NSAutoreleasepool

本文介绍了Xcode中@autoreleasepool的使用方式及其相对于NSAutoreleasePool的优势。在使用自动引用计数(ARC)的情况下,推荐使用@autoreleasepool块来提高效率。
@autoreleasepool 代替 NSAutoreleasepool 

新的xcode的holle world开始给人的印象就是简洁了,可是到底哪里发生了变化呢?原来是原先的NSAutoreleasepool被@autoreleasepool所替代。一下来自苹果官方手册,我做了一下翻译。


NSAutoreleasePool 类 参考手册


继承自
NSObject
Conforms to
NSObject (NSObject)
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in Mac OS X v10.0 and later.
相关教程
Advanced Memory Management Programming Guide
声明
NSAutoreleasePool.h
Related sample code
CocoaSpeechSynthesisExample
OpenCL NBody Simulation Example
SpellingChecker CarbonCocoa Bundled
SpellingChecker-CarbonCocoa
SpellingChecker-CocoaCarbon


概览
The NSAutoreleasePool class is used to support Cocoa’s reference-counted memory management system. An autorelease pool stores objects that are sent a release message when the pool itself is drained.


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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值