RetainCount OK to use in this instance?

前端 未结 2 595
-上瘾入骨i
-上瘾入骨i 2021-01-20 23:44

RetainCount == BAD

retainCount is taboo, unreliable, unpredictable, and in general shouldn\'t be used. I don\'t use it anywhere in my code, but I have se

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 00:25

    Nope. You're relying on an abstracted implementation which publicly bears the sign "Keep Out" on its gate.

    Just manage your dependencies using your own memory and implementation. This might include an ivar and/or methods for completion/destruction phases.

    See also the documentation for release:

    release

    Decrements the receiver’s reference count. (required)

    - (oneway void)release

    Discussion

    The receiver is sent a dealloc message when its reference count reaches 0.

    You would only implement this method to define your own reference-counting scheme. Such implementations should not invoke the inherited method; that is, they should not include a release message to super.

    If you want to be sure your program behaves correctly across multiple releases, it's best to change it now.

提交回复
热议问题