• OC3_dealloc


    //
    //  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;
    }
  • 相关阅读:
    razor 拼接字符串
    转,CV和resume的区别
    b/s开发者的困境
    sql 下,float和numeric
    VS2010 + Entity FrameWork 4.4 +Mvc 4.0 出现的错误
    Nuget 管理entity framework
    关于 Code First
    C# 输出控制台结果到文件
    WCF wsdlexception(at/html):faultCode=INVALID_WSDL
    Silverlight环境配置
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586945.html
Copyright © 2020-2023  润新知