ARC instance variable retain release

五迷三道 提交于 2019-12-02 12:19:03
Martin R

First of all the usual disclaimer: the absolute value of the retain count does not tell you anything useful, for more information see

Now in your case, in the line

NSLog(@"%ld", CFGetRetainCount((__bridge CFTypeRef)object));

you read the value of a weak pointer, and the Clang/ARC documentation 4.2 Semantics states about that:

For __weak objects, the current pointee is retained and then released at the end of the current full-expression.

Therefore the object's retain count is increased by one while passed to CFGetRetainCount(). You can see that also in the generated assembly code:

movq    %rbx, %rdi
callq   _objc_retain
movq    %rax, %rbx
.loc    1 21 0                  
movq    %rbx, %rdi
callq   _CFGetRetainCount
movq    %r15, %rdi
movq    %rax, %rsi
xorb    %al, %al
callq   _NSLog
movq    _objc_release@GOTPCREL(%rip), %r12
movq    %rbx, %rdi
callq   *%r12
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!