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

后端 未结 3 2038
渐次进展
渐次进展 2020-12-10 11:06

In many Books and on many Sites I see -drain. Well, for an Autorelease Pool that sounds cool. But does it do anything other than an release? I would guess -drain just makes

相关标签:
3条回答
  • 2020-12-10 11:51

    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.

    0 讨论(0)
  • 2020-12-10 11:53

    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.

    0 讨论(0)
  • 2020-12-10 12:01

    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

    0 讨论(0)
提交回复
热议问题