[英]weak referenced Delegates becomes nil
I'm creating a delegate with weak reference and need to go through the couple of completions(closures) then delegate
becomes nil. 我正在创建一个引用弱的委托,并且需要经历几个完成(关闭),然后
delegate
变为零。 When I remove the weak
reference it works fine. 当我删除
weak
引用时,它可以正常工作。
weak var contentDelegate: ContentDelegate?
Actually is it allow to create a delegate property without weak
reference in swift best practices? 实际上它允许创建没有委托物业
weak
在迅速的最佳实践的参考? What are the drawbacks? 有什么缺点?
Actually is it allow to create a delegate property without weak reference in swift best practices?
实际上是否允许在没有快速参考的最佳实践的情况下创建委托属性? What are the drawbacks?
有什么缺点?
Yes you can create delegates without weak
reference . 是的,您可以创建没有
weak
引用的委托。
No it's not under best practices scope . 不,这不在最佳实践范围内。
Drawbacks, are mainly the risk of having a retain cycle where references are not getting released from memory, leading to a memory leak . 缺点是存在保留周期的风险,其中引用不会从内存中释放出来,从而导致内存泄漏。
would be great if you can share your code. 如果您可以共享代码,那就太好了。 Without code hard to say, but looks like you have async calls, and on some async call
delegate
, I suppose it's controller or maybe some service, released from the memory 没有代码很难说,但是看起来您有异步调用,并且在某些异步调用
delegate
,我想它是控制器或从内存中释放的某些服务
if you remove weak
you will get retain cycle, when delegate
and owner of this delegating are holding each other in the memory 如果删除
weak
,则将获得保留周期,当此delegate
和所有者在内存中相互保持时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.