`
alex09
  • 浏览: 969369 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

objective-c 中retain,assign,copy

阅读更多
"The assign keyword will generate a setter which assigns the value to the instance variable directly, rather than copying or retaining it. This is best for primitive types like NSInteger and CGFloat, or objects you don't directly own, such as delegates."

The reason that you avoid retaining delegates is that you need to avoid a retain loop:

A creates B A sets itself as B's delegate … A is released by its owner

If B had retained A, A wouldn't be released, as B owns A, thus A's dealloc would never get called, causing both A and B to leak.

You shouldn't worry about A going away b/c it owns B and thus gets rid of it in dealloc.
   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics