Objective-C block——block保留它引用的对象吗?

时间:2022-06-07 16:58:40

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?

如果在进行异步操作时我正在使用块,而块引用视图控制器的对象和属性,那么如果用户在异步操作结束之前离开视图控制器,那么块是否保留它们,从而使视图控制器无法解除分配?

1 个解决方案

#1


8  

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

是的。块是Objective-C对象,它将保留任何引用的对象。当然,你可以要求他们不要这么做。

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

见:http://thirdcog.eu/pwcblocks/ objcblocks

#1


8  

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

是的。块是Objective-C对象,它将保留任何引用的对象。当然,你可以要求他们不要这么做。

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

见:http://thirdcog.eu/pwcblocks/ objcblocks