[英]ALAssetsLibrary resultBlock weak or strong reference
For the call 对于电话
[library assetForURL:referenceURL resultBlock:^(ALAsset *asset){...}
If I am to pass the image to an ImageView, should I pass the ImageView with a weak reference or should it be a strong reference? 如果我要将图像传递给ImageView,我应该以弱引用传递ImageView还是将其作为强引用? Can I ever go wrong with passing a weak reference?
通过弱引用会不会出错? By weak reference I mean
弱引用是指
__weak MyVC *weakSelf = self;
....
weakSelf.myImageView...
Block retains the object they reference and in turn will create a retain cycle. 块保留它们引用的对象,并依次创建一个保留周期。 In your above code snippet, the block creates the retain cycle, you need to use weak reference to break the retain cycle as
在上面的代码片段中,该块创建了保留周期,您需要使用弱引用来打破保留周期,因为
__weak typeof(self) *weakself = self;
or you can also implement it in following way 或者您也可以按照以下方式实施
__block MyVC *blockSelf = self;
and reference the blockSelf inside the block. 并在块内引用blockSelf。
This avoids the cycle, because blockSelf is not retained 这样可以避免循环,因为未保留blockSelf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.