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;
}

 

posted @ 2015-06-19 18:48  sirzhang  阅读(209)  评论(0编辑  收藏  举报
AmazingCounters.com