Skip to main content

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



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 the Pool to -release all it's objects, without releasing the Pool itself. Just a guess.





Source: Tips4all

Comments

  1. 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.

    ReplyDelete
  2. 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.

    ReplyDelete
  3. 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

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?