zoukankan      html  css  js  c++  java
  • OC6_复合类的类存管理

    //
    //  Person.h
    //  OC6_复合类的类存管理
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Dog.h"
    
    @interface Person : NSObject
    
    @property (retain, nonatomic) Dog *dog;
    
    @end
    
    
    
    //
    //  Person.m
    //  OC6_复合类的类存管理
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Person.h"
    
    @implementation Person
    
    - (void)dealloc
    {
        NSLog(@"%@:dog is release", [self class]);
       [_dog release];
        [super dealloc];
    }
    
    
    @end
    //
    //  Dog.h
    //  OC6_复合类的类存管理
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Dog : NSObject
    
    @property (copy, nonatomic) NSString *name;
    @property (assign,nonatomic) NSInteger age;
    
    @end
    
    
    
    //
    //  Dog.m
    //  OC6_复合类的类存管理
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Dog.h"
    
    @implementation Dog
    
    - (void)dealloc
    {
        NSLog(@"%@: dog name is release!!!", [self class]);
        [_name release];
        [super dealloc];
    }
    
    @end
    //
    //  main.m
    //  OC6_复合类的类存管理
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Person.h"
    #import "Dog.h"
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            // insert code here...
            //NSLog(@"Hello, World!");
            Person *xiaoHua = [[Person alloc] init];
            Dog *xiaoHei = [[Dog alloc] init];
            xiaoHei.name = @"小黑";
            //setter方法
            xiaoHua.dog = xiaoHei ;    //  [xiaoHei retain]
            NSLog(@"%li----",xiaoHua.retainCount);
            NSLog(@"xiao%li----",xiaoHei.retainCount);
            
          Person *p =[xiaoHua retain];
          // NSLog(@"xiaohei%li----",xiaoHei.retainCount);
          // NSLog(@"tt%li----",p.retainCount);
           //[xiaoHua release];
            
            NSLog(@"最后%li----",xiaoHei.retainCount);
    
            [xiaoHei release];
        }
        return 0;
    }
  • 相关阅读:
    oracle后台进程详解
    解决表格撑开浏览器问题,即自动换行问题
    文件后缀名修改或添加——字符串转换
    Struts1 action重定向跳转 带参数
    js 正则表达式
    js获取焦点
    select值的获取及修改
    iframe自适应高度,根据src中页面来得到。
    今个忽然晓得,原来radio不是普通去获取值的!
    查询时,如何保存获取相关路径url
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586956.html
Copyright © 2011-2022 走看看