本帖最后由 Freedam 于 2014-6-8 10:47 编辑
直接上代码:
Car.h
- #import <Foundation/Foundation.h>
- @interface Car : NSObject
- @end
复制代码
Car.m
- #import "Car.h"
- @implementation Car
- @end
复制代码
main.m
- #import <Foundation/Foundation.h>
- #import "Car.h"
- int main(int argc, const char * argv[])
- {
- Car *c = [[Car alloc] init];
- NSLog(@"Car is %ld",[c retainCount]);
-
- [c release];
- //[c release];
- NSLog(@"Car is %ld",[c retainCount]);
- return 0;
- }
复制代码
运行结果:
- 2014-06-07 10:58:18.068 dui[745:303] Car is 1
- 2014-06-07 10:58:18.071 dui[745:303] Car is 1
- Program ended with exit code: 0
复制代码
我想问Car类型的对象已经release了,为什么retainCount还能返回1啊?难道是计数器在对象回收了之后又保存了一份? |