来自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的解释理解的更多相关文章

  1. iOS 中strong,weak,copy,assign区别

    1:ARC环境下,strong代替retain.weak代替assign2:weak的作用:在ARC环境下,,所有指向这个对象的weak指针都将被置为nil.这个T特性很有用,相信很多开发者都被指针指 ...

  2. ios中strong, weak, assign, copy

    copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是 ...

  3. IOS开发 strong,weak,retain,assign,copy nomatic 等的区别与作用

    strong,weak,retain,assign,copy nomatic 等的区别 copy与retain:1.copy其实是建立了一个相同的对象,而retain不是:2.copy是内容拷贝,re ...

  4. iOS 之 Strong与Weak,_unsafe _unretained与weak区别

    1. 在ARC中 strong(强引用) 相当于retain, weak(弱引用) 相当于assign.ARC下,strong告诉编译器自动插入retain.但是在ARC下,代理协议的属性依然用ass ...

  5. iOS strong 和weak的形象理解

    转自:http://hi.baidu.com/phone_lwc/item/c36e5bfe1cf9c313ce9f32be 觉得讲的很容易理解 The difference is that an o ...

  6. @property中strong跟weak的区别

    strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *string1; @property ...

  7. iOS中respondsToSelector与conformsToProtocol的相关理解和使用

    respondsToSelector相关的方法 : -(BOOL) isKindOfClass: classObj 用来判断是否是某个类或其子类的实例 -(BOOL) isMemberOfClass: ...

  8. 浅谈iOS中的单例模式

    iOS中的单例模式     就我本身理解而言,我认为的单例:单例在整个工程中,就相当于一个全局变量,就是不论在哪里需要用到这个类的实例变量,都可以通过单例方法来取得,而且一旦你创建了一个单例类,不论你 ...

  9. IOS中@property的属性weak、nonatomic、strong、readonly等介绍

    iOS开发中@property的属性weak nonatomic strong readonly等介绍 //property:属性://synthesize:综合; @property与@synthe ...

随机推荐

  1. linux 环境变量PATH路径的三种方法

    转:http://www.jb51.net/LINUXjishu/150167.html 总结:修改1.#PATH=$PATH:/etc/apache/bin  或者#vi /etc/profile ...

  2. post multipart data boundary问题 使用curl 向jersey post文件

    原以为curl 模拟post file跟post string类似,-d参数一加 ,header一加就完了,这次遇到个问题,却怎么都搞不定. curl模拟post提交 与客户端定的协议是: Heade ...

  3. Java类文件最大限制

    今天在往一个jsp文件里添加代码时,项目跑起来访问这个jsp时报错.. The code of method _jspService(HttpServletRequest, HttpServletRe ...

  4. 前端获取url参数

    function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  5. [css3]圆盘旋转动画

    效果:打开只能看到logo,鼠标放上去,圆盘渐显放大旋转展示出来 知识点: [html+css] 1.logo水平垂直居中于圆盘内,用到的样式 position: absolute; left: 0; ...

  6. python 从文件导入分类

    # -*- coding:utf-8 -*- """ 从文件导入分类 根据行首制表符或空格确定层级关系(4个空格等于一个制表符 同一行制表符和空格不能混用 ) 必须是 u ...

  7. [vijos P1083] 小白逛公园

    不知怎地竟有种错觉此题最近做过= =目测是类似的?那道题貌似是纯动归? 本来今晚想做两道题的,一道是本题,一道是P1653疯狂的方格取数或NOI08 Employee,看看现在的时间目测这个目标又达不 ...

  8. CBC和CTR解密模式——C++实现

    利用已经封装好的AES加密算法,实现CBC模式加密和CTR模式加密. (1)CBC解密 如图,CBC模式的解密,步骤主要有三个,首先是拿密文段逐一放到AES解密盒子里面得到一个结果temp(事先要把密 ...

  9. BZOJ 4326 树链剖分+二分+差分+记忆化

    去年NOIP的时候我还不会树链剖分! 还是被UOJ 的数据卡了一组. 差分的思想还是很神啊! #include <iostream> #include <cstring> #i ...

  10. C++ 基本知識回顧

    ---------------------------------------------------------------------------------------------------- ...