ERROR已修复 [2015-11-16 02:05] │ entry #4794

NSAutoreleasePool报错的问题

2015 年 11 月 16 日 │ 编程开发 │ 0 评论 │ 阅读 6
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
 
//omitted
    
[pool drain];
return 0;

程序报错为”NSAutoreleasePool is unavailable: not available in automatic reference counting mode”.

在网上查阅了一些资料,Xcode4.2之后的版本中引入了ARC特性来自动管理内存,应该如下

@autoreleasepool{
    //omitted.
}

经过测试发现,直接不写这几行代码,也是完全可以编译通过和正常执行的。无论Objective-C,Swfit还是XCode,都在不断的变化,要时时刻刻学习新的东西,很多教材的一些东西已经过时了。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。