Objective-C ARC: strong vs retain and weak vs assign

后端 未结 8 2482
眼角桃花
眼角桃花 2020-11-22 15:59

There are two new memory management attributes for properties introduced by ARC, strong and weak.

Apart from copy, which is ob

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 16:01

    The differences between strong and retain:

    • In iOS4, strong is equal to retain
    • It means that you own the object and keep it in the heap until don’t point to it anymore
    • If you write retain it will automatically work just like strong

    The differences between weak and assign:

    • A “weak” reference is a reference that you don’t retain and you keep it as long as someone else points to it strongly
    • When the object is “deallocated”, the weak pointer is automatically set to nil
    • A "assign" property attribute tells the compiler how to synthesize the property’s setter implementation

提交回复
热议问题