weak
来源:互联网 发布:彩票现在有网络销售吗 编辑:程序博客网 时间:2024/05/21 06:30
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
- -weak
- Weak Reference
- Weak Alias
- weak alias
- __attribute__((weak))
- __attribute__((weak))
- __attribute__((weak))
- weak & asign
- __attribute__((weak))
- __attribute__((weak))
- weak alias
- Weak NSTimer
- strong weak
- __attribute__((weak))
- __attribute__((weak))
- 关于weak
- #pragma weak
- 浅析 with check option
- ajax传参
- PHP 实现301转向代码
- linux根文件系统的类别和区别
- 软件开发中团队首领的好坏之分
- weak
- 常用资源整理
- sdfsdfsd
- centos源码安装mysql5.6
- post-gis.sql函数
- linux C中调用shell命令和运行shell脚本
- Java生成验证码
- UI第七章多视图应用
- Android:onOptionsItemSelected、onMenuItemSelected、onContextItemSelected 区别