iOS strong 和weak的形象理解(真的很精典!)
来源:互联网 发布:张大奕的淘宝店 编辑:程序博客网 时间:2024/06/05 06:42
觉得讲的很容易理解
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型指针都将会被清除。
- iOS strong 和weak的形象理解(真的很精典!)
- iOS strong 和weak的形象理解(真的很精典!)
- iOS strong 和weak的形象理解(真的很精典!)
- iOS strong 和weak的形象理解(真的很精典!)
- iOS strong 和weak的形象理解
- iOS strong 和weak的形象理解
- iOS strong 和weak的形象理解
- [iOS]arc机制中strong和weak的形象理解
- 转:iOS strong 和weak的形象理解
- iOS strong 和weak的形象理解(我服了!)
- iOS strong 和weak的理解
- strong 和weak的理解
- iOS 之weak和strong的简单理解
- ios中strong和weak的解释理解
- IOS开发(87)之Strong与Weak的理解
- objective-c 中weak和strong使用的区别(很形象)
- iOS5中strong和weak的理解
- ios weak和strong使用的区别
- asp.net,jsp,php,安卓Android,ios计算机毕业课程设计源码免费打包下载
- Xsolla对话成都游戏茶馆CEO
- Android入门第八篇之GridView(九宫图)
- Natural Language Processing (nlp) 路线图
- BZOJ 2982 combination Lucas定理
- iOS strong 和weak的形象理解(真的很精典!)
- strong和weak的区别
- uva1586分子量
- Ehcache缓存配置
- 给小吴:从实践下手去学编程
- 写程序是创作过程
- ubuntu14.04设置联网----中国移动有线网络
- 分组急救技能竞赛方法在急诊专科护士培训中的运用
- powershell 针对日志的实例