Understanding the amount of hold with blocking access to it inside.

I have a basic understanding of weak block references. The problem I am facing is

Whenever I access myself inside the block, the value of saving self increases by 2 , where when I access self inside the default block (UIViewAnimation example), keep the counter for myself increases by 1.

I just wanted to understand why it is increasing by 2. enter image description here

Thanks in advance!

+4
source share
2 answers

According to Clang source code for generating Objective-C block code.

Objective-C block literal EmitBlockLiteral.

llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {

LLVM , -. . self.

buildBlockDescriptor -> buildCopyHelper -> GenerateCopyHelperFunction

GenerateCopyHelperFunction Clang objc_storeStrong auto Objective-C, .

for (const auto &CI : blockDecl->captures()) {
    ...
    EmitARCStoreStrongCall(...

, self (1 β†’ 2).

EmitBlockLiteral objc_retain auto Objective-C, .

// Next, captured variables.
for (const auto &CI : blockDecl->captures()) {
    ...
    EmitExprAsInit -> EmitScalarInit -> EmitARCRetain

, self (2 β†’ 3).

. , -, , Objective-C .

+1

self , , 2. , .

, ,

-
  __unsafe_unreteded typeof (self) weakSelf = self;

-1

Source: https://habr.com/ru/post/1569706/


All Articles