//
// Person.h
// OC5_复合类的内存管理
//
// Created by zhangxueming on 15/6/18.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Person : NSObject
//先release 再 copy
@property (copy,nonatomic) NSString *firstName;
//先release 再 retain
@property (retain, nonatomic)NSString *lastName;
//直接赋值
@property (assign, nonatomic)NSString *fullName;
@end
//
// Person.m
// OC5_复合类的内存管理
//
// Created by zhangxueming on 15/6/18.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import "Person.h"
@implementation Person
//在类内类外都应该遵守内存管理法则
- (void)dealloc
{
NSLog(@"firstName release!!!");
[_firstName release];
NSLog(@"lastName release!!!");
[_lastName release];
[super dealloc];
}
@end
//
// main.m
// OC5_复合类的内存管理
//
// Created by zhangxueming on 15/6/18.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *xiaoHua = [[Person alloc] init];
[xiaoHua release];
}
return ;
}