码迷,mamicode.com
首页 > 其他好文 > 详细

OC5_复合类的内存管理

时间:2015-06-18 22:05:09      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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 0;
}

 

OC5_复合类的内存管理

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4586952.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!