4

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)

Community
  • 1
  • 1
Jay
  • 19,649
  • 38
  • 121
  • 184

1 Answers1

4

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
  • 81,520
  • 17
  • 180
  • 200
  • Thanks for clearing that up. It didnt occur to me to read the Apple docs to understand non apple libraries (: – Jay Sep 27 '09 at 13:47
  • -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 Sep 27 '09 at 22:08