大家好:
我们都知道,在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呢?
这个问题在stackoverflow上是有人问过了
Why is the retainCount still 1 after {object release}?
大意是说这个方法在调试时是不靠谱的,本人理解不能,题主自己看看。