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

OC3_dealloc

时间:2015-06-18 21:46:54      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

//
//  Dog.h
//  OC3_dealloc
//
//  Created by zhangxueming on 15/6/18.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Dog : NSObject

@end



//
//  Dog.m
//  OC3_dealloc
//
//  Created by zhangxueming on 15/6/18.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "Dog.h"

@implementation Dog

- (void)dealloc
{
    NSLog(@"dog release!!!");
    [super dealloc];
}

@end
//
//  main.m
//  OC3_dealloc
//
//  Created by zhangxueming on 15/6/18.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Dog.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Dog *xiaoHei = [[Dog alloc] init];
        Dog *xiaoBai = [xiaoHei retain];
        NSLog(@"retainCount = %li", xiaoBai.retainCount);
        Dog *xiaoHui = [xiaoHei retain];
        NSLog(@"retainCount = %li", xiaoHui.retainCount);
        [xiaoHei release];
        NSLog(@"retainCount = %li", xiaoBai.retainCount);
        [xiaoBai release];
        NSLog(@"retainCount = %li", xiaoHui.retainCount);
        
        //最后一次release 的时候,retainCount理论值为的0, 自动调用dealloc方法释放对象
        [xiaoHui release];
        
        
        
    }
    return 0;
}

 

OC3_dealloc

标签:

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

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