6日目-ARCで自動リリースプール

2380 ワード

//
//  main.m
//  10-ARC      
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CZPerson.h"
/*
              ,                     
 
*/
int main(int argc, const char * argv[]) {
    @autoreleasepool {
    
       CZPerson *person = [CZPerson person];
  
       @autoreleasepool{
        
            @autoreleasepool {
                CZDog *dog = [[CZDog alloc] init];
                person.dog = dog;
            }
           CZDog *dog  = person.dog;
           dog = nil;
        }
    }
    return 0;
}

//
//  CZPerson.h
//  1201-    
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CZDog.h"

@interface CZPerson : NSObject

+ (instancetype) person;

@property (nonatomic,strong) CZDog *dog;

@end

//
//  CZPerson.m
//  1201-    
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import "CZPerson.h"

@implementation CZPerson

+ (instancetype) person
{
    return  [[self alloc] init];
}

-(void)dealloc
{
    //            
    NSLog(@"%s",__func__);
    //    [super dealloc];
}

@end


//
//  CZDog.h
//  1201-    
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CZDog : NSObject

@end

//
//  CZDog.m
//  1201-    
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import "CZDog.h"

@implementation CZDog


-(void)dealloc
{
    //            
    NSLog(@"%s",__func__);
    //    [super dealloc];
}

@end




//
//  main.m
//  11-   
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014  itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        for (long i = 0; i < NSIntegerMax; i++) {
             @autoreleasepool {
                   NSString *str =  [NSString stringWithFormat:@"  %@",@"  "];
                   str = [str uppercaseString];
                   str = [str lowercaseString];
                   str = [str capitalizedString];
             }
        }
        
    }
    return 0;
}