week 与 strong区别 精辟的解释
转: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区别 精辟的解释的更多相关文章
- @proprety数组字典字符串用copy和strong区别(深浅拷贝)
//// @proprety数组字典字符串用copy和strong区别(深浅拷贝).h// IOS笔记//// /* _proprety________copy_strong_________h ...
- ios中strong和weak的解释理解
来自stackoverflow解释的挺有意思的 Imagine our object is a dog, and that the dog wants to run away (be dealloca ...
- setTimeout setInterval 区别 javascript线程解释
原文:http://www.iamued.com/qianduan/1645.html 今天看到这篇文章,学到了不少东西 特此发出来 和大家分享 JavaScript的setTimeout与setIn ...
- Python2x,3x源码的区别,编译型解释型,变量,注释,if,用户交互input,基本数据类型3种
cpu 内存 硬盘 操作系统 cpu: 计算机的运算和计算中心,相当于人类的大脑. 内存:暂时存储数据,临时加载数据应用程序,4G,8G,16G,32G #速度快,造价高,断电即消失 硬盘 ...
- HashMap 和 Hashtable两者的区别以和解释
HashMap 和 Hashtable 是 Java 开发程序员必须要掌握的,也是在各种 Java 面试场合中必须会问到的. 但你对这两者的区别了解有多少呢? 现在,栈长我给大家总结一下,或许有你不明 ...
- 【Java面试题】3 Java的"=="和equals方法究竟有什么区别?简单解释,很清楚
==操作符专门用来比较两个变量的值是否相等,也就是用于比较变量所对应的内存中所存储的数值是否相同,要比较两个基本类型的数据或两个引用变量是否相等,只能用==操作符. 如果一个变量指向的数据是对象类型的 ...
- border:0与border:none区别与联系
联系:前台效果均实现了无边框 区别: 要解释区别,首先得先介绍一下border这个属性. border是一个简写属性.可以设置如下属性 border-width border-style border ...
- linux命令行下命令参数前的一横(-)和两横(--)的区别
原文转自:http://blog.csdn.net/songjinshi/article/details/6816776 在解释这些区别之前我们先了解一下有关linux的背景知识,这个需要大家先认真看 ...
- C/C++静态数组与动态数组的区别
简介 以下三行代码有什么区别? int a[10]; int *a = (int*)malloc(sizeof(int)*10); int *a = new int[10]; 第一行代码定义a为包含1 ...
随机推荐
- mysql-5.6.27源码安装及错误解决办法
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.27.tar.gz yum install -y cmake 当然也可以自己下载源码包安 ...
- zookeeper_01:zookeeper概述
应对场景: 相对于开发在一台计算机上运行的单个程序,如何让一个应用中的多个独立的程序协同工作是一件非常困难的事情.开发这样的应用,很容易让很多开发人员陷入如何使多个程序协同工作的逻辑中,最后导致没有时 ...
- c++对文件操作的支持(一)
#include <stdio.h> #include <iostream> #include <fstream> using namespace std; voi ...
- 从汇编看c++的new和delete
下面是c++源码: class X { private: int _x; public: X() : _x(xx) {} ~X() {} }; int main() { X* xp = new X; ...
- 求double类型的n次方
剑指offer系列面试题 package com.study; /* * 数值的整数次方 * 要求:实现函数 double Power(double base, int exponent) 求base ...
- python版去UTF-8 BOM
今天给app弄银联支付接口.直接copy银联的sdk.结果.安卓和ios始终报json格式错误.找了半天.都没找到问题.最后怀疑可能是BOM破坏了json的数据格式转换.验证后确认是BOM的问题.为方 ...
- 喷水装置(一)--nyoj题目6
喷水装置(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中 ...
- 1.C语言关键字(auto break case char const swtich)
ANSI C标准C语言共有32个关键字,分别为: auto break case char const continue default do double else enum extern floa ...
- 定制化Azure站点Java运行环境(5)
Java 8下PermGen及参数设置 在上一章节中,我们定制化使用了Java 8环境,使用我们的测试页面打印出了JVM基本参数,但如果我们自己观察,会发现在MXBeans中,没有出现PermGen的 ...
- Nginx的HTTP模块
1.HTTP的核心模块.这些HTTP模块会在编译Nginx时自动编译进来,除非使用configure命令禁止编译这些模块.(1)alias指令.该指令用于在URL和文件系统路径之间实现映射.它与roo ...