ios中strong和weak的解释理解
来自stackoverflow解释的挺有意思的
Imagine our object is a dog, and that the dog wants to run away (be deallocated). Strong pointers are like a leash on the dog. As long as you have the leash attached to the dog, the dog will not run away. If five people attach their leash to one dog, (five strong pointers to one object), then the dog will not run away until all five leashes are detached. Weak pointers, on the other hand, are like little kids pointing at the dog and saying "Look! A dog!" As long as the dog is still on the leash, the little kids can still see the dog, and they'll still point to it. As soon as all the leashes are detached, though, the dog runs away no matter how many little kids are pointing to it. As soon as the last strong pointer (leash) no longer points to an object, the object will be deallocated, and all weak pointers will be zeroed out. When we use weak? The only time you would want to use weak, is if you wanted to avoid retain cycles (e.g. the parent retains the child and the child retains the parent so neither is ever released).
weak/atrong主要是为了避免循环强引用 比如父类中含有子类{父类retain了子类},子类中又调用了父类{子类又retain了父类},这样都无法release
这是里面的关键。例子想想再写,先发表吧。会宿舍碎觉~
ios中strong和weak的解释理解的更多相关文章
- iOS 中strong,weak,copy,assign区别
		
1:ARC环境下,strong代替retain.weak代替assign2:weak的作用:在ARC环境下,,所有指向这个对象的weak指针都将被置为nil.这个T特性很有用,相信很多开发者都被指针指 ...
 - ios中strong, weak, assign, copy
		
copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是 ...
 - IOS开发 strong,weak,retain,assign,copy nomatic 等的区别与作用
		
strong,weak,retain,assign,copy nomatic 等的区别 copy与retain:1.copy其实是建立了一个相同的对象,而retain不是:2.copy是内容拷贝,re ...
 - iOS 之 Strong与Weak,_unsafe _unretained与weak区别
		
1. 在ARC中 strong(强引用) 相当于retain, weak(弱引用) 相当于assign.ARC下,strong告诉编译器自动插入retain.但是在ARC下,代理协议的属性依然用ass ...
 - iOS strong 和weak的形象理解
		
转自:http://hi.baidu.com/phone_lwc/item/c36e5bfe1cf9c313ce9f32be 觉得讲的很容易理解 The difference is that an o ...
 - @property中strong跟weak的区别
		
strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *string1; @property ...
 - iOS中respondsToSelector与conformsToProtocol的相关理解和使用
		
respondsToSelector相关的方法 : -(BOOL) isKindOfClass: classObj 用来判断是否是某个类或其子类的实例 -(BOOL) isMemberOfClass: ...
 - 浅谈iOS中的单例模式
		
iOS中的单例模式 就我本身理解而言,我认为的单例:单例在整个工程中,就相当于一个全局变量,就是不论在哪里需要用到这个类的实例变量,都可以通过单例方法来取得,而且一旦你创建了一个单例类,不论你 ...
 - IOS中@property的属性weak、nonatomic、strong、readonly等介绍
		
iOS开发中@property的属性weak nonatomic strong readonly等介绍 //property:属性://synthesize:综合; @property与@synthe ...
 
随机推荐
- stash存储
			
比如我的fsm_ngh分支,被a修改了,可是我本地还有没有提交的东西,就不能切换分支也不能下拉,也不能直接上传,否则分支会混乱. 这个时候stash的优点来了,先把你修改的暂存隐藏起来,然后pull远 ...
 - HTML“计算机输出”标签 <code><kbd><samp><tt><var><pre>
			
我们并不反对使用它们,但是如果您只是为了达到某种视觉效果而使用这些标签的话,我们建议您使用样式表,那么做会达到更加丰富的效果. <code> 标签-定义计算机代码文本. 定义和用法: &l ...
 - C#微信公众号开发-高级接口-之模板消息开发,附源码
			
个人觉得模板消息功能的增加对公众号的作用非常大,可以说是真正意义上的实现了所谓的轻app,商家可以通过模板消息给用户发送重要的信息,交易.预约.消费.邮件.物流等信息.之前我做过的系统通过邮件发送订单 ...
 - iOS开发UI篇—UIScrollView控件实现图片轮播
			
iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播 二.实现代码 storyboard中布局 代码: #import "YYV ...
 - bzoj 2878: [Noi2012]迷失游乐园
			
#include<iostream> #include<cstring> #include<cstdio> #define M 100005 #define ld ...
 - sql float 转换为 nvarchar
			
INSERT INTO CC11 SELECT convert(nvarchar(30),convert(decimal(11,0),PCTID)),convert(nvarchar(30),conv ...
 - Rhel6-mpich2 hpc集群配置文档
			
系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.121 server21.example.com 192.168.12 ...
 - HTTP 304
			
304 的标准解释是:Not Modified 客户端有缓冲的文档并发出了一个条件性的请求(一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档).服务器告诉客户,原来缓冲的 ...
 - 黑马程序员——OC语言Foundation框架 (2) NSArray  NSSet NSDictionary\NSMutableDictionary
			
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)NSArray 1>NSArray :不可变数组 ①创建方法 ...
 - qt搭建环境
			
1 用viewteam实现远程控制电脑.可以在家里继续操作办公电脑了. http://blog.csdn.net/sch0120/article/details/38324599 2qt环境安装.今天 ...