OC1_类方法的内存管理

//

//  Dog.h

//  OC1_类方法的内存管理

//

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

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

//



#import <Foundation/Foundation.h>



@interface Dog : NSObject





+ (Dog *)dogCreat;



@end





//

//  Dog.m

//  OC1_类方法的内存管理

//

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

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

//



#import "Dog.h"



@implementation Dog



//类方法里面也要遵守内存管理法则

+ (Dog *)dogCreat

{

    return [[[Dog  alloc] init] autorelease];

}



- (void)dealloc

{

    NSLog(@"dog is release");

    [super dealloc];

}

@end







//

//  main.m

//  OC1_类方法的内存管理

//

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

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

//



#import <Foundation/Foundation.h>

#import "Dog.h"



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

    @autoreleasepool {

        

        Dog *dog = [Dog dogCreat];

        

        

    }

    return 0;

}

 

你可能感兴趣的:(内存管理)