objective-c - [pool release] 和 [pool drain] 有什么区别?

标签 objective-c

<分区>

Possible Duplicate:
What's the difference between sending -release or -drain to an Autorelease Pool?

我一直想知道 [pool release] 和 [pool drain] 之间的区别。

我们在IOS中创建基于View的应用时,使用[pool release]。

当我们在 MAX OS X 中创建命令行工具时,使用 [pool drain]。

为什么要以不同的方式使用它们?

最佳答案

来自documentation :

In a garbage-collected environment, there is no need for autorelease pools. You may, however, write a framework that is designed to work in both a garbage-collected and reference-counted environment. In this case, you can use autorelease pools to hint to the collector that collection may be appropriate. In a garbage-collected environment, sending a drain message to a pool triggers garbage collection if necessary; release, however, is a no-op. In a reference-counted environment, drain has the same effect as release. Typically, therefore, you should use drain instead of release.

关于objective-c - [pool release] 和 [pool drain] 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139420/

相关文章:

iphone - Json在iphone中传递

ios - 如何确定 DDXMLElement 是否有值?

ios - 导航栏和主屏幕上的 UIImageView

ios - 处理游戏进入后台

ios - 这个效果叫什么?

objective-c - GPUImage 显示图像而不是实时视频

iOS内存管理属性

iphone - 重用 subview

ios - UITextField 阻止 UITableViewCell 内的滚动

ios - iPhone 5 与 iPhone 4 的图像命名