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;
    }
  • 相关阅读:
    进程管理 2
    进程管理 1
    Linux进程
    分配swap分区
    磁盘分区与挂载
    文件系统常用命令
    多线程
    系统hosts文件的作用
    sql 连接查询的区别 inner,left,right,full
    sql 游标
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586945.html
Copyright © 2011-2022 走看看