OC2_인용 계수

8002 단어 인용 하 다.
//

//  Dog.h

//  OC2_    

//

//  Created by zhangxueming on 15/6/18.

//  Copyright (c) 2015  zhangxueming. All rights reserved.

//



#import <Foundation/Foundation.h>



@interface Dog : NSObject

{

    NSString *_name;

    NSInteger _age;

}



@property (copy, nonatomic) NSString *name;

@property (nonatomic)NSInteger age;



@end









//

//  Dog.m

//  OC2_    

//

//  Created by zhangxueming on 15/6/18.

//  Copyright (c) 2015  zhangxueming. All rights reserved.

//



#import "Dog.h"



@implementation Dog



@end
//

//  main.m

//  OC2_    

//

//  Created by zhangxueming on 15/6/18.

//  Copyright (c) 2015  zhangxueming. All rights reserved.

//



#import <Foundation/Foundation.h>

#import "Dog.h"



//      :

//       automic refence counting

//       manual refence counting



//gar --> automic refence counting  yes --> no



int main(int argc, const char * argv[]) {

    @autoreleasepool {

        Dog *xiaoBai = [[Dog alloc] init];

        

        NSLog(@"retainCount = %li", xiaoBai.retainCount);

        

        //       ,         ,      1;

        //retain           

        

        Dog *xiaoHei = [xiaoBai retain];

        //Dog *xiaoHei = xiaoBai;   xiaohei     xiaobai ,   retainCount 1.

        NSLog(@"retainCount = %li", xiaoHei.retainCount);

    

        Dog *xiaoFei = [xiaoHei retain];

        NSLog(@"retainCount = %li", xiaoFei.retainCount);

    

        //release        ,        -1;

        [xiaoBai release];

        xiaoBai = nil;

        NSLog(@"retainCount = %li", xiaoFei.retainCount);

        

        [xiaoHei release];

        xiaoHei = nil;

        NSLog(@"retainCount = %li", xiaoFei.retainCount);

        

        [xiaoFei release];//retainCount = 0 dealloc

        xiaoFei = nil;

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

//        NSLog(@"      ,       ");

    //       ,           

    // NSLog(@"retainCount = %li", xiaoFei.retainCount);

    }

    return 0;

}

좋은 웹페이지 즐겨찾기