views:

105

answers:

1

According to another Stack Overflow post the drain message is an Apple-only call:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello");
[pool drain];
return 0;

Is it safe to replace drain with release? I am trying to port an Objective-C application to run on Linux (Ubuntu at the moment). Should I give up even before I have started? (I'm already having issues trying to get NSURLConnection working)

+3  A: 

From Apple's documentation of drain:

[...] this method behaves the same as release. [...]

So draining an autorelease pool means deallocating it inevitably. In my opinion, Apple should deprecate drain since it only creates confusion.

But:

Special Considerations:
In a garbage-collected environment, release is a no-op, so unless you do not want to give the collector a hint it is important to use drain in any code that may be compiled for a garbage-collected environment.

Nikolai Ruhe
Thanks for clearing that up. It didnt occur to me to read the Apple docs to understand non apple libraries (:
Jacob
-drain will not be -- will never be -- deprecated exactly because it supports the garbage collector. This is a critical boon to performance in code that must run both GC and non-GC, such as certain plug-ins and the system frameworks.
bbum