首页 > 其他 > 详细

ARC How the strong reference works

时间:2014-04-10 03:24:03      阅读:468      评论:0      收藏:0      [点我收藏+]

How the strong reference works
id __strong obj0 = [[NSObject alloc] init];

/*
* obj0 has a strong reference to object A*/

id __strong obj1 = [[NSObject alloc] init];

/*
* obj1 has a strong reference to object B*/

id __strong obj2 = nil;

/*
* obj2 has no reference*/

obj0 = obj1;

/*
*Obj0 has a strong reference to object B,
* So, obj0 does not have a strong reference to object A anymore.

*  Object A is disposed of because no one has ownership of it.

*  At this moment, both obj0 and obj1 have strong references to object B.

*/ 

obj2 = obj0; 

/*

*  Through  obj0, obj2 has a strong reference to object B.

*

*  At this moment, obj0, obj1 and obj2 have strong references to object B. 

*/ 


obj1 = nil; 

/*

*  Because  nil is assigned to obj1, strong references to object B disappear. 

*  At this moment, obj0, and obj2 have strong references to object B. 

*/ 


obj0 = nil; 

/*

*  Because  nil is assigned to obj0, strong references to object B disappear. 

*  At this moment, obj2 have strong references to object B. 

*/


obj2 = nil; 

/*

*  Because  nil is assigned to obj2, strong references to object B disappear. 

*  Object B is disposed of because no one has ownership of it 
 

*/




ARC How the strong reference works,布布扣,bubuko.com

ARC How the strong reference works

原文:http://blog.csdn.net/majiakun1/article/details/23283883

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!