当前位置:网站首页>Why use weak pointers for delegation- Why use weak pointer for delegation?

Why use weak pointers for delegation- Why use weak pointer for delegation?

2022-07-05 23:26:00 javail

problem :

I can't understand why it is correct to define a delegate with weak pointer : I don't understand why it's right to define delegates with weak pointers :

@property (nonatomic,weak) id delegate;

I can't realize why isn't necessary to retain a reference to the delegate... i don't want the object that i use as the delegate to be deallocated... thus, i would prefer using a strong reference not a weak! I don't understand why it's unnecessary to keep references to delegates ... I don't want to release the object used as a delegate ... therefore , I'd rather use strong references than weak ones !

In many cases the delegate is the same object where the instance of my class will be created, in this case creating a weak reference would be a great solution to avoid retain cycle... but what if I choose a totally different object as the delegate ? in many instances , A delegate is an object that will create an instance of a class , under these circumstances , Creating weak references will be a good way to avoid retention periods ... But if I choose a completely different object as a delegate , What should I do ? ?

I searched for other questions on stack overflow but I can't find something that can help me to fully understand this situation. I searched for other issues related to stack overflow , But I can't find any problems that can help me fully understand this situation .


Solution :

Reference resources : https://stackoom.com/en/question/ZRyq
原网站

版权声明
本文为[javail]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140319175789.html