您的位置:首页 > 移动开发 > Objective-C

Objective-C Autorelease Pool 的实现原理

2017-07-04 15:18 288 查看
毫无疑问,看源代码是理解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 的实现原理
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  objc 自动释放池