Possible Duplicate:
What's the difference between sending -release or -drain to an Autorelease Pool?
I just got always wondered about difference between [pool release] and [pool drain]..
When we create a View-based application in IOS, use [pool release].
When we c开发者_StackOverflow中文版reate a command-line Tool in MAX OS X, use [pool drain].
why do use them differently?
From the 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.
No difference unless you're using Garbage Collection on OSX. Exactly the same on iOS and OSX w/o GC.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html
joe
精彩评论