猿问

NSAutoreleasePool和autoreleasepool的区别

NSAutoreleasePool的官方解释
ImportantIfyouuseAutomaticReferenceCounting(ARC),youcannotuseautoreleasepoolsdirectly.Instead,youuse@autoreleasepoolblocksinstead.Forexample,inplaceof:NSAutoreleasePool*pool=[[NSAutoreleasePoolalloc]init;
//Codebenefittingfromalocalautoreleasepool.
[poolrelease];youwouldwrite:@autoreleasepool{
//Codebenefittingfromalocalautoreleasepool.
}@autoreleasepoolblocksaremoreefficientthanusinganinstanceofNSAutoreleasePooldirectly;youcanalsousethemevenifyoudonotuseARC.xcode4.3引入ARC,release这块就有些变化,当你使用ARC,就必须将NSAutoreleasePool的地方换成@autoreleasepoolhttp://marshal.easymorse.com/archives...
子衿沉夜
浏览 234回答 2
2回答

慕田峪9158850

两者的作用时间不一样。AutoReleasePool对象的写法作用于运行时,@autoreleasepool作用于编译阶段。如果要启用ARC的话,在编译阶段就需要告诉编译器启用自动引用计数管理,而不能在运行时动态添加。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答