"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.
分享到:
相关推荐
Google Objective-C Style Guide 中文版 目录 例子 空格与格式 空格与制表符 行宽 方法声明与定义 方法调用 @public与@private 异常 协议 命名 文件名 Objective-C++ 类名 分类名 Objective-C方法名 变量名 注释 ...
Objective-C内存管理课件.docx ,assign,retain,copy
@property中的retain,copy,assign区别
retain和copy还有assign的区别
在objective-c中,内存的引用计数一直是一个让人比较头疼的问题。尤其是当引用计数涉及到arc、blocks等等的时候。似乎ARC的出现只是让我们解放了双手,由于底层实现依然依赖引用计数,所以开启ARC后,只有对引用计数...
针对iOS 对象的属性的关键字(retain/assign/readonly等)的区别。彻底解决您的疑惑。
详细讲解了ios中常用关键字的使用方法的区别,着重讲解了assign,retain,copy之间的区别
@property (nonatomic, retain) NSMutableString *currentResult; @property (nonatomic, retain) NSMutableDictionary *map; @property (nonatomic, retain) NSMutableArray *list; -(NSMutableDictionary *)...
Objective-C提供了一系列的内存管理规则,包括MRC(Manual Reference Counting)中的`retain`、`release`和`autorelease`概念,以及在ARC(Automatic Reference Counting)中由编译器自动插入内存管理代码的机制。...
对于Retain和Assign属性的理解
IOS中(assign,retain,copy,weak,strong)的区别以及nonatomic的含义 我们在声明@property 属性时,总是要在括号中写上assign、retain、copy、weak、strong中的一个,很多时候,我们仅仅只是按照习惯去写经常写...
RH附加这些年来,为我服务良好的各种Objective-C类别和附加功能。 希望那时也能为您服务!执照根据修改后的BSD许可证发布。 (需要注明出处) RHAdditionsCopyright (c) 2011-2013 Richard Heard. All rights ...
RETAIN-Keras:重新实现RETAIN的Keras ,它允许创建高度可解释的递归神经网络模型以进行患者诊断,而不会降低模型性能 该存储库保留了Keras对RETAIN的重新实现,可以灵活地修改原始代码,引入了多个新功能,并提高...
在ARC出现以前,程序员们只能靠retain/relese/autorelease来确保对象们恰好“坚持”到被需要的那一刻。如果忘了retain,或者多次release某个对象,程序就会发生内存泄漏的问题,甚至直接崩溃。 在Xcode 4.2中,除了...
主要介绍了iOS开发之详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic的相关资料,需要的朋友可以参考下
自定义对象要实现归档必须实现NSCoding协议 NSCoding协议有两个方法,encodeWithCoder方法对... @property(nonatomic,retain)NSString *name; @property(nonatomic,retain)NSString *email; @property(nonatomic,r
SAS-The RETAIN Statement; Retain的用法,英文版。
FastCopy ver2.08 2011/02/28 SHIROUZU Hiroaki FastCopy is the Fastest Copy/Delete Software on Windows. It can copy/delete unicode and over MAX_PATH(260byte) pathname files. It always run by ...
) 该项目还包括一个 Objective-C 类EBChannel ,它包装了 C 库并允许通过 Objective-C 块使用更方便的select语句语法。 (请参阅下面的示例。)支持的平台eb_chan支持 Mac OS X、iOS 和 Linux。一体化eb_chan作为...