Search code examples
objective-cgnustepnsautoreleasepool

GNUStep NSAutoreleasePool incompatibility


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)


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.