惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - wqlblogger

验证未来 Objective-C ARC下的内存管理(一) 摩托罗拉 Milestone新手刷机教程 C 语言 运算符优先级 CorelDraw, Adobe Illustrator 转换到 Photoshop 形状路径 PS: 操作不实时显示的解决办法 禁用Windows XP的自动播放功能 语丝 Source Insight 快捷键 及 常用设置 汇总 360给腾讯造的盗梦空间 Linux inird 入门及制作 极度讽刺——读《coders at work》有感 天天撞墙 用户体验经典解释 这个真的有!——《hello world 大全》 编程隐喻:合适的工具链 还想说两句——致非开发一线的同行们 iphone版 helloworld 原来曾经有人支持过我,感动!
ARC下的内存管理(二)对象及成员的引用关系
wqlblogger · 2013-06-08 · via 博客园 - wqlblogger

ARC下的内存管理(二)对象及成员的引用关系

程序清单2-1

myObjStrong = [[MyObject alloc] init];

myObjStrong.strStrong = [array objectAtIndex:5];

myObjStrong.strWeak = [array objectAtIndex:6];

__weak MyObject *myObjWeak;    

myObjWeak = myObjStrong; 

下面“释放”weak对象的strong成员:

myObjWeak.strStrong = nil;

考虑以下输出各是什么:

NSLog(@"weak object's stong member:%@", myObjWeak.strStrong);

NSLog(@"strong object's strong member:%@", myObjStrong.strStrong);

观察结果

 

可见:弱对象的成员就是强对象成员本身

对比执行:

程序清单2-2

myObjWeak.strWeak = nil;

NSLog(@"weak object's weak member:%@", myObjWeak.strWeak);

NSLog(@"strong object's strong member:%@", myObjStrong.strStrong);

NSLog(@"strong object's weak member:%@", myObjStrong.strWeak);

以上输出为:

 

进一步观察array中的值

程序清单2-3

NSLog(@"string 5:%@",  [array objectAtIndex:5]);
NSLog(@"string 6:%@", [array objectAtIndex:6]);

 

原字符串对象并没有被释放

实际上由于strong属性的array存在,无论是将 myObjWeak还是 myObjStrong置空(=nil)都不能释放其中的string;

思考题:

将myObject放入array中,分别做weak和strong的引用,是否能通过引用释放array中的myObject的成员?