本帖最后由 Hi围城 于 2014-3-28 20:56 编辑
- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- @property (nonatomic, assign) double height;
- @property (nonatomic, assign, setter = setGood:) int weight;
- @property (nonatomic, assign) int age;
- @property (nonatomic, assign, getter = isRich) BOOL rich;
- @property (retain) NSString *name;
- @end
- int main()
- {
- Person *p = [[Person alloc] init];
- p.rich = YES;
- BOOL b = p.isRich;
- NSLog(@"%d", b);
- p.weight = 60;
- NSLog(@"%d", p.weight);
- NSString *str = @"Tom";
- p.name = str;
-
- [p release];
- NSLog(@"%ld", [str retainCount]); // 输出的结果为什么为-1?到这步,内存释放干净了吗?
- return 0;
- }
- @implementation Person
- - (void)dealloc
- {
- [_name release];
- NSLog(@"人没了,名还在?");
- [super dealloc];
- }
- @end
- // 字符串的内存是咋个回收的?
复制代码 |