Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C blocks - does block retain the object it references?

If I am using a block when making an asynchronous operation and the block references objects and properties of the view controller, does the block retain them and thereby making the view controller not get deallocated if the user leaves the view controller before the async operation ends?

like image 771
Boon Avatar asked Mar 12 '26 23:03

Boon


1 Answers

Yes. Blocks are Objective-C objects and will retain any referenced objects. You can ask them not to, of course.

See: http://thirdcog.eu/pwcblocks/#objcblocks

like image 94
gregheo Avatar answered Mar 14 '26 13:03

gregheo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!