佚名通过本文主要向大家介绍了retaincount,环境问题,环境问题有哪些,营商环境存在的问题,生态环境问题等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:mrc 一个关于MRC环境下retainCount的问题
描述:
解决方案1:
描述:
大家好:
我们都知道,在MRC中,使用alloc创建的对象的retainCount会为1,release之后retainCount会减1。那么当我执行了以下代码:
Something *sth = [[Something alloc]init];
NSLog(@"%zd", [sth retainCount]);
[sth release];
NSLog(@"%zd", [sth retainCount]);
打印内容如下:
2016-07-22 10:35:19.737 TestMemoryManagement[52759:3120736] 1
2016-07-22 10:35:19.738 TestMemoryManagement[52759:3120736] -[Something dealloc]
2016-07-22 10:35:19.738 TestMemoryManagement[52759:3120736] 1
为什么最后的retainCount还是1呢?
解决方案1:
这个问题在stackoverflow上是有人问过了
Why is the retainCount still 1 after {object release}?
大意是说这个方法在调试时是不靠谱的,本人理解不能,题主自己看看。