zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Python-pymysql
    MySQL学习(3)
    MySQL学习(1)
    MySQL与PostgreSQL哪个更好?
    svn与git区别
    journalctl常用命令
    Spring Cloud 生产环境性能优化
    springcloud优雅停止上下线与熔断
    istio基础详解
    微服务的全链路监控
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586945.html
Copyright © 2011-2022 走看看