So basically, if you are running on OS X 10.9+ or iOS 7+, autoreleasing on a thread without a pool should not lead to a leak. This is not documented and is an internal implementation detail, so be careful relying on this as Apple could change it in a future OS. However, I don't see any reason why they would remove this feature as it is simple and only has benefits and no downsides, unless they completely re-write the way autorelease pools work or something.

The Objective-C runtime is open-source so you can read the source to see what's going on. The latest version of the runtime (646, which shipped with OS X 10.10 and iOS 8) does indeed add a pool if you perform an autorelease without a pool on the current thread. In NSObject.mm:

static __attribute__((noinline))
id *autoreleaseNoPage(id obj)
{
// No pool in place.
assert(!hotPage()); if (obj != POOL_SENTINEL && DebugMissingPools) {
// We are pushing an object with no pool in place,
// and no-pool debugging was requested by environment.
_objc_inform("MISSING POOLS: Object %p of class %s "
"autoreleased with no pool in place - "
"just leaking - break on "
"objc_autoreleaseNoPool() to debug",
(void*)obj, object_getClassName(obj));
objc_autoreleaseNoPool(obj);
return nil;
} // Install the first page.
AutoreleasePoolPage *page = new AutoreleasePoolPage(nil);
setHotPage(page); // Push an autorelease pool boundary if it wasn't already requested.
if (obj != POOL_SENTINEL) {
page->add(POOL_SENTINEL);
} // Push the requested object.
return page->add(obj);
}

最新文章

  1. 如何解决自动加载与模板中(如Smarty)的自动加载冲突的问题
  2. Unity 用户手册用户指南二维纹理 (Texture 2D)
  3. Java_Servlet 中文乱码问题及解决方案剖析
  4. EF 关系规则(一对一、一对多、多对多...)
  5. C++常见gcc编译链接错误解决方法
  6. <《巴菲特之道 (第三版)》>读书笔记
  7. php向队列服务里插入一条insert sql例如
  8. GNU Binutils工具
  9. linux是实时系统还是分时操作系统
  10. GA遗传算法解析
  11. HTML之打开/另存为/打印/刷新/查看原文件等按钮的代码
  12. css中盒子宽高的auto
  13. CPU Affinity
  14. C盘里的桌面文件移到E盘里了,然后E盘里的文件都显示到桌面上了,怎么将桌面文件还原回C盘
  15. IOS @proporty 关键字(一)retain strong
  16. C#之Using(转)
  17. java的this关键字理解
  18. mongodb学习(入门。。。。。)
  19. 51nod 1387 移数字
  20. MHA环境搭建

热门文章

  1. [Xcode 实际操作]五、使用表格-(6)UITableView滑动到指定单元格
  2. 大话Spark(2)-Spark on Yarn运行模式
  3. Redis内核原理及读写一致企业级架构深入剖析1-综合组件环境实战
  4. 软件包管理(rpm&yum)
  5. AT2582 Mirrored
  6. Python网络爬虫(二)
  7. Ubuntu14.04升级到Ubuntu16.04
  8. 使用:/usr/bin/phpize 报错
  9. Python3基础(2)模块、数据类型及运算、进制、列表、元组、字符串操作、字典
  10. SpringBoot | 第十八章:web应用开发之WebJars使用