I found a strange keyword in NSObject.h
- (oneway void)release;
I searched the web, and learned it relates to asynchronous message passing, which looks similar with Erlang's message passing.
It seems this can make many interesting things. What are some good use-cases of this keyword?
oneway
is used with the distributed objects API, which allows use of objective-c objects between different threads or applications. It tells the system that it should not block the calling thread until the method returns. Without it, the caller will block, even though the method's return type is void. Obviously, it is never used with anything other than void, as doing so would mean the method returns something, but the caller doesn't get it.
For more on distributed objects, see Cocoa Conceptual DistrObjects.
It also appears to be necessary to eliminate a warning with XCode 4.2 (LLVM). Specifically:
-(void) release { }
gives the following warning in XCode 4.2 (with LLVM):
warning: Semantic Issue: Conflicting distributed object modifiers on return type in implementation of 'release'
The warning can be eliminated by adding the oneway modifier:
-(oneway void) release { }
This is in the implementation of a singleton so release really does not do anything.
This is necessary (at least to eliminate the warning) on iOS as well as OS X. The NSObject protocol in the iOS docs defines release as (oneway void) even though there are no Distributed Objects in iOS. It appears that LLVM picks this up whereas GCC does not.
According to Apple's documentation oneway is only used for distributed object (and not for multithreading).
The oneway modifier is only used if the object is remote. In this case the release call can return asynchronously (before the method has terminated). In a network it makes sense because waiting for a return message can take a while.
The release method has no return value and so call it can be executed asynchronously. In contrast, retain and autorelease return an id and so we have to wait for the return message to be transferred throughout the network.