Why can't ARC use a 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 instead?:
Object *strongObject = objc_loadWeakRetained(weakObject);
[strongObject doSomething];
objc_release(strongObject);
I'd like to do away with as many autoreleases in ARC as possible. I do a lot of async threading with GCD and I end up having to add autorelease pools a lot:
dispatch_async(self.myQueue, ^{
@autoreleasepool{
[weakObject doSomethingBig];
}
});
I cannot explain why the ARC compiler does it this way, but if I understand the generated assembly code correctly, using the following pattern
dispatch_async(self.myQueue, ^{
Object *strongObject = weakObject;
[strongObject doSomething];
});
is translated into objc_loadWeakRetained()
, ..., objc_release()
, so that the object
is not put into an autorelease pool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With