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

无人久伴 提交于 2019-11-28 10:47:07

Note that the comments on oxigen's answer saying that -drain does not release the NSAutoreleasePool are not correct. The documentation for NSAutoreleasePool clearly says that -drain releases (and thus destroys) the NSAutoreleasePool.

-drain is a replacement for using -release for NSAutoreleasePool objects, the only difference being that provides a hint to the garbage collection system.

If your system has a garbage Collection, then -drain send message (objc_collect_if_needed) for GC

If you haven't GC, then drain = release

Oxigen is right, see the documentation for method drain of NSAutoreleasePool:

In a reference-counted environment, releases and pops the receiver; in a garbage-collected environment, triggers garbage collection if the memory allocated since the last collection is greater than the current threshold.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!