开发者

What is difference between [pool release] and [pool drain]? [duplicate]

开发者 https://www.devze.com 2023-03-30 03:53 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: What's the difference between sending -release or -drain to an Autorelease Pool?
This question already has answers here: Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消