strong & weak

Here is a quick summary: A strong reference will keep the object it points to from being deallocated. A
weak reference will not. Thus instance variables and properties that are marked as weak are pointing at
objects that might go away. If this happens, that instance variable or property will be set to nil, instead
of continuing to point to where the object used to live.

时间: 2024-08-05 19:21:24

strong & weak的相关文章

assign/copy/retain/strong/weak/readyonly/readwrite/nonatomic/atomic

arc其实并不是所谓的垃圾回收机制,其实arc只是编译器的一种特性,编译器会在编译阶段插入相应的内存管理代码,以实现自动的内存管理,这样就减少了因为程序员的一时疏忽或者项目过大而失误从而造成内存泄露,因为是编译器自动完成的代码插入所以arc的效率要高于垃圾回收机制. 在arc机制下dealloc中会由编译器自动插入释放属性的代码因此也不需要手动调用[super dealloc],当然arc只能管理foundation层的对象对于core foundation层的变量需要程序员手动去释放或者使用桥

对于atomic nonatomic assign retain copy strong weak的简单理解

atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作 1)atomic 设置成员变量的@property属性时,atomic是默认值,提供多线程安全 在多线程环境下,原子操作是必要的,否则有可能引起错误的结果.加了atomic后setter函数会变成下面这样: {lock} if (property != newValue) { [property release]; property = [newValue retain]; } {unlock} 2)n

iOS strong & weak 简析

不用arc的话strong weak 相当于: strong 用来修饰强引用的属性: @property (strong) SomeClass * aObject; 对应原来的 @property (retain) SomeClass * aObject; 和 @property (copy) SomeClass * aObject; weak 用来修饰弱引用的属性:@property (weak) SomeClass * aObject; 对应原来的 @property (assign) So

关于@property()的那些属性及ARC简介【nonatomic,atomic,assign,retain,strong,weak,copy。】

@property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作. NSObject对象的@property属性时,默认为atomic,提供多线程安全. 在多线程环境下,原子操作是必要的,否则有可能引起错误的结果.加了atomic,setter函数会变成下面这样: NSLock *_lock = [[NSLock alloc]ini

atomic nonatomic assign retain copy strong weak 介绍

atomic和nonatomic用来决定编译器生成的getter和setter是否为原子操作.         atomic 设置成员变量的@property属性时,默认为atomic,提供多线程安全. 在多线程环境下,原子操作是必要的,否则有可能引起错误的结果.加了atomic,setter函数会变成下面这样:                        {lock}                                if (property != newValue) {    

ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy)

ARC声明属性关键字详解(strong,weak,unsafe_unretained,copy) 在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了,在此我也不介绍,网上有很多相关文章. 但是在iOS 5中加入ARC,产生了几个新的关键字strong, weak, unsafe_unretained.  我们可以将其与以前的关键字对应学习: strong与retain类似,weak和unsafe_unretained这两个新关键字与assign类

assign,copy,strong,weak,nonatomic的具体理解

例子: NSString *houseOfMM = [[NSString alloc] initWithString:'MM的三室两厅']; 上面一段代码会执行以下两个动作:  1 在堆上分配一段内存用来存储@' MM的三室两厅 ' ,比如:内存地址为 0X1111  内容为 ' MM的三室两厅' ,  2 在栈上分配一段内存用来存储 houseForWife ,比如:地址为 0XAAAA  内容自然为 0X1111 下面分别看下(assign,retain,copy):  1.assign的情

copy, retain, assign , readonly , readwrite,strong,weak,nonatomic整理

copy:建立一个索引计数为1的对象,然后释放旧对象 对NSString对NSString 它指出,在赋值时使用传入值的一份拷贝.拷贝工作由copy方法执行,此属性只对那些实行了NSCopying协议的对象类型有效.更深入的讨论,请参考“复制”部分. retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1对其他NSObject和其子类对参数进行release旧值,再retain新值指定retain会在赋值时唤醒传入值的retain消息.此属性只能用于Objective

ios中strong, weak, assign, copy

copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是copy,那copy与strong的情况下到底有什么区别呢? 比如: @property (retain,nonatomic) NSString *rStr; @property (copy, nonatomic)   NSString *cStr; - (void)test: { NSMutabl

iOS--合理定义对象的引用类型strong/weak/assign/copy

在ios中一定要合理使用对象的引用类型: 最佳原则:在ios中任何一个对象只有一个强引用 使用weak的情况: 1.懒加载的方式需要使用weak修饰: 如@property(nonatmic,weak) IBOutlet UILabel *lbl; 备注:所谓的懒加载就是指控件通过IB拖到根视图中,再通过连线的方式与ViewController中的属性对应起来.此种方式就相当于self.view执行了addSubview()方法,即self.view对该控件做了强引用,那么在viewContro