为什么delegate在声明属性的时候要使用assign?
来源:互联网 发布:网络上写文章怎么赚钱 编辑:程序博客网 时间:2024/05/17 04:50
今天一位同事问我为什么在Objective-C中delegate声明属性的时候要使用assign。在网上查了一下资料,归结为Objective-C中的内存管理问题,直接把老外的answer copy了过来:
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.
链接:http://stackoverflow.com/questions/918698/why-are-objective-c-delegates-usually-given-the-property-assign-instead-of-retain
应该看得懂吧。stackoverflow的确很好用啊,解决了我不少的技术问题。
- 为什么delegate在声明属性的时候要使用assign?
- delegate申请属性的时候为什么用assign而不是retain
- 为什么delegate属性使用assign而不是retain?
- 为什么delegate属性使用assign而不是retain?
- 为什么delegate属性使用assign而不是retain?
- delegate为什么用assign声明
- delegate或者protocol申请属性的时候为什么用assign而不是retain
- 在UIView中创建 delegate的属性的时候一定要用assign,不能用retain
- 为什么delegate属性要用assign不能用retain?
- 为什么id delegate 用的是assign
- 为什么id delegate 用的是assign
- 为什么很多内置类如 UITableViewController 的 delegate 属性都是 assign 而不是 retain 的
- 为什么很多内置类如UITableViewController的delegate属性都是assign而不是retain的
- IOS-为什么很多内置类如UITableViewController的delegate属性都是assign而不是retain的?
- 为什么很多内置类如UITableViewController的delegate属性都是assign而不是retain的?
- 为什么很多内置类如UITableViewController的delegate属性都是assign而不是retain?
- 为什么delegate属性使用delegate而不是retain?
- 为什么delegate属性使用delegate而不是retain?
- 2010-10-21
- mstsc使用
- WCF 大并的性能测试和调优
- 比较排序算法
- windows phone 试练连连看
- 为什么delegate在声明属性的时候要使用assign?
- ArcGIS Viewer for Flex新鲜出炉!
- 浅谈 Linux 内核开发之网络设备驱动
- 俞永福炮轰腾讯剽窃UC桌面:不罚剽窃谁愿再创新
- 多谢csdn.net
- 种上你想要收获的东西
- 写日志xml
- 精通oracle 10g系统管理.pdf
- 数据结构转换(http://topic.csdn.net/u/20101021/17/86aa8d23-baa3-406c-97e4-dbf7f273e215.html)