Why ARC abstract when using weak links?

Why can't ARC use regular release?

Example:

[weakObject doSomething]; 

From what I understand, ARC turns this into:

 Object *strongObject = objc_autorelease(objc_loadWeakRetained(weakObject)); [strongObject doSomething]; 

Why doesn't ARC do this ?:

 Object *strongObject = objc_loadWeakRetained(weakObject); [strongObject doSomething]; objc_release(strongObject); 

I would like to do away with as many auto-rales in ARC as possible. I make a lot of asynchronous threads with GCD, and I end up having to add a lot of autodetection pools:

 dispatch_async(self.myQueue, ^{ @autoreleasepool{ [weakObject doSomethingBig]; } }); 
+6
source share
1 answer

I can’t explain why the ARC compiler does it this way, but if I understood the generated assembly code correctly using the following template

 dispatch_async(self.myQueue, ^{ Object *strongObject = weakObject; [strongObject doSomething]; }); 

translates to objc_loadWeakRetained() , ..., objc_release() , so the object does not fit into the auto-advertisement pool.

+2
source

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


All Articles