转:http://stackoverflow.com/questions/9262535/explanation-of-strong-and-weak-storage-in-ios5 
觉得讲的很容易理解

The difference is that an object will be deallocated as soon as there are no strong pointers to it. Even if weak pointers point to it, once the last strong pointer is gone, the object will be deallocated, and all remaining weak pointers will be zeroed out.

Perhaps an example is in order.

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.

(weak和strong)不同的是 当一个对象不再有strong类型的指针指向它的时候 它会被释放  ,即使还有weak型指针指向它。

一旦最后一个strong型指针离去 ,这个对象将被释放,所有剩余的weak型指针都将被清除。

可能有个例子形容是妥当的。

想象我们的对象是一条狗,狗想要跑掉(被释放)。

strong型指针就像是栓住的狗。只要你用牵绳挂住狗,狗就不会跑掉。如果有5个人牵着一条狗(5个strong型指针指向1个对象),除非5个牵绳都脱落 ,否着狗是不会跑掉的。

weak型指针就像是一个小孩指着狗喊到:“看!一只狗在那” 只要狗一直被栓着,小孩就能看到狗,(weak指针)会一直指向它。只要狗的牵绳脱落,狗就会跑掉,不管有多少小孩在看着它。

只要最后一个strong型指针不再指向对象,那么对象就会被释放,同时所有的weak型指针都将会被清除。

week 与 strong区别 精辟的解释的更多相关文章

  1. @proprety数组字典字符串用copy和strong区别(深浅拷贝)

    ////  @proprety数组字典字符串用copy和strong区别(深浅拷贝).h//  IOS笔记//// /* _proprety________copy_strong_________h ...

  2. ios中strong和weak的解释理解

    来自stackoverflow解释的挺有意思的 Imagine our object is a dog, and that the dog wants to run away (be dealloca ...

  3. setTimeout setInterval 区别 javascript线程解释

    原文:http://www.iamued.com/qianduan/1645.html 今天看到这篇文章,学到了不少东西 特此发出来 和大家分享 JavaScript的setTimeout与setIn ...

  4. Python2x,3x源码的区别,编译型解释型,变量,注释,if,用户交互input,基本数据类型3种

    cpu 内存 硬盘 操作系统 ​ cpu: 计算机的运算和计算中心,相当于人类的大脑. ​ 内存:暂时存储数据,临时加载数据应用程序,4G,8G,16G,32G #速度快,造价高,断电即消失 ​ 硬盘 ...

  5. HashMap 和 Hashtable两者的区别以和解释

    HashMap 和 Hashtable 是 Java 开发程序员必须要掌握的,也是在各种 Java 面试场合中必须会问到的. 但你对这两者的区别了解有多少呢? 现在,栈长我给大家总结一下,或许有你不明 ...

  6. 【Java面试题】3 Java的"=="和equals方法究竟有什么区别?简单解释,很清楚

    ==操作符专门用来比较两个变量的值是否相等,也就是用于比较变量所对应的内存中所存储的数值是否相同,要比较两个基本类型的数据或两个引用变量是否相等,只能用==操作符. 如果一个变量指向的数据是对象类型的 ...

  7. border:0与border:none区别与联系

    联系:前台效果均实现了无边框 区别: 要解释区别,首先得先介绍一下border这个属性. border是一个简写属性.可以设置如下属性 border-width border-style border ...

  8. linux命令行下命令参数前的一横(-)和两横(--)的区别

    原文转自:http://blog.csdn.net/songjinshi/article/details/6816776 在解释这些区别之前我们先了解一下有关linux的背景知识,这个需要大家先认真看 ...

  9. C/C++静态数组与动态数组的区别

    简介 以下三行代码有什么区别? int a[10]; int *a = (int*)malloc(sizeof(int)*10); int *a = new int[10]; 第一行代码定义a为包含1 ...

随机推荐

  1. JDBC插入百万数据,不到5秒!

    java自带的批量操作,就可以很好的支持大量数据的处理.相比c#,简单很多.c#要使用oracle提供的ODP.NET,效率才很高,但是代码却很复杂.总之,在这方面,c#没得比.当然,这里的表是没加索 ...

  2. DevExpress中SearchLookUpEdit用法总结

    在前一个项目中用到了DevExpress,需要搜索某一个字段,来拉取出对应的相关信息,比来比去,发现SearchLookUpEdit的用户体验更好,但自己是个不折不扣的C#和DevExpress的初学 ...

  3. Hortonworks 用于做 Sentimental Analysis的Hiveddl.sql 文件

    The hiveddl.sql script has performed the following steps to refine the data: Converted the raw Twitt ...

  4. Linux命令备忘录

    1.tar命令 解压tar.gz格式压缩包:tar zxvf xxx.tar.gz 解压tar.bz2格式压缩包:tar jxvf xxx.tar.bz2 压缩为tar.gz格式压缩包:tar zcv ...

  5. C++程序设计实践指导1.4正整数转换为字符串改写要求实现

    改写要求1:改为适合处理超长整数 #include <cstdlib> #include <iostream> #include <string> using na ...

  6. mysql中select into 和sql中的select into 对比

    现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去.answer 01: create table dust select * from student;//用于复制前未 ...

  7. python 源代码分析之调试设置

    首先在官方下载源代码,我下载的是最新版本3.4.3版本:https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz 解压后的目录如下(借用网上的目 ...

  8. Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. Nginx Http模块开发

    关于Nginx Http模块开发的文章非常少,只有Emiler的那篇关于Http模块的文章,但是那篇文章里面,并没有说到事件型的模块如何进行开发.而且文章里面提到的内容实在是让人有点意犹未尽.因此,对 ...

  10. How to delete the icons of Win7 desktop shortcuts

    1. Copy the following bat code in txt type file, 2. save it as file extension type bat, run it as ad ...