Objective-C Autorelease Pool 的实现原理

毫无疑问,看源代码是理解objc各种机制最有效的手段。(然而,我还没怎么看)凡是有水平的讲解语法的博文,无一不有实现源代码的展示,就像下文提到的讲解autoreleasepool的文章。好吧!先不管是否理解到,先说出通过文章get到的点:(其实苹果的官方文档里关于使用自动释放池已经给出了建议)

  • 如果你编写的程序不是基于 UI 框架的,比如说命令行工具;
  • 如果你编写的循环中创建了大量的临时对象;
  • 如果你创建了一个辅助线程。

对应的英文文档如下:

  • If you are writing a program that is not based on a UI framework, such as a command-line tool.
  • If you write a loop that creates many temporary objects.
    You may use an autorelease pool block inside the loop to dispose of those objects before the next iteration. Using an autorelease pool block in the loop helps to reduce the maximum memory footprint of the application.
  • If you spawn a secondary thread.
    You must create your own autorelease pool block as soon as the thread begins executing; otherwise, your application will leak objects.

雷纯锋的技术博客:Objective-C Autorelease Pool 的实现原理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值