Use-case of `oneway void` in Objective-C?

后端 未结 2 719
南笙
南笙 2020-12-07 09:00

I found a strange keyword in NSObject.h

- (oneway void)release;

I searched the web, and learned it relates to asynchronous message passing,

2条回答
  •  臣服心动
    2020-12-07 09:58

    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.

提交回复
热议问题