ios中strong和weak的解释理解
来源:互联网 发布:人工智能 百度网盘 编辑:程序博客网 时间:2024/05/16 05:10
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的解释理解
- [iOS]arc机制中strong和weak的形象理解
- iOS strong 和weak的理解
- iOS strong 和weak的形象理解
- iOS strong 和weak的形象理解
- iOS strong 和weak的形象理解
- iOS5中strong和weak的理解
- iOS中strong和weak的区别
- strong 和weak的理解
- 转:iOS strong 和weak的形象理解
- iOS 之weak和strong的简单理解
- Object-C strong和weak的解释
- iOS中strong&weak和_block&_weak的作用比较
- 在ios开发中weak和strong的使用问题
- IOS strong 和 weak
- ios strong和weak
- [ios] strong和weak
- ios strong和weak
- 歌词加载学习笔记
- 在ios8中做的屏幕旋转功能
- 积累的 Android 开发各种开源库
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 封装实现一个自己的tabbar
- ios中strong和weak的解释理解
- duplicate symbols for architecture armv7解决办法
- 关于编程上的一些建议
- 关于block的一些理解
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptabl
- loadView、viewDidLoad、initWithCoder、initWithNibName、awakeFromNib的用法
- Java Socket网络编程的经典例子(转)
- 什么是一个对象?
- collectionview使用