Question

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)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top