Instance Method インスタンスメソッド

retain

Increments the receiver’s reference count.

Declaration 宣言

- (instancetype)retain;

Return Value 戻り値

self.

Discussion 解説

You send an object a retain message when you want to prevent it from being deallocated until you have finished using it.

An object is deallocated automatically when its reference count reaches 0. retain messages increment the reference count, and release messages decrement it. For more information on this mechanism, see Advanced Memory Management Programming Guide.

As a convenience, retain returns self because it may be used in nested expressions.

You would implement this method only if you were defining your own reference-counting scheme. Such implementations must return self and should not invoke the inherited method by sending a retain message to super.

Special Considerations 特別な注意事項

Instead of using manual reference counting, you should adopt ARC—see Transitioning to ARC Release Notes.

See Also 参照

Obsolete Methods