Differences between strong and weak in Objective-C

后端 未结 9 1244
礼貌的吻别
礼貌的吻别 2020-11-22 08:09

I\'m new to Obj-C, so my first question is:

What are the differences between strong and weak in @property declarations of poin

9条回答
  •  一向
    一向 (楼主)
    2020-11-22 08:32

    strong: assigns the incoming value to it, it will retain the incoming value and release the existing value of the instance variable

    weak: will assign the incoming value to it without retaining it.

    So the basic difference is the retaining of the new variable. Generaly you want to retain it but there are situations where you don't want to have it otherwise you will get a retain cycle and can not free the memory the objects. Eg. obj1 retains obj2 and obj2 retains obj1. To solve this kind of situation you use weak references.

提交回复
热议问题