zoukankan      html  css  js  c++  java
  • autorelease应用

    //

    //  main.m

    //  02-autorelease应用

    //

    //  Created by apple on 14-3-18.

    //  Copyright (c) 2014年 apple. All rights reserved.

    //

    #import <Foundation/Foundation.h>

    #import "Chief.h"

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

    {

        @autoreleasepool {

        

            /*

            Chief * chi  = [[Chief alloc] init];

            Food * food = [chi makeFood];;

            

            NSLog(@"%@",food.name);//[nil name];

            

            [chi release];

            */

            

            

            Chief * chi = [Chief chief];

            Food * food = [chi chiefMakeFood];

            

            NSLog(@"%@",food.name);

            

            NSString * name = [NSString stringWithFormat:@"%@",@"施瓦辛格"];//都是autorelease

            NSLog(@"%@",name);

            

        }

        return 0;

    }

    //

    //  Chief.m

    //  01-autorelease基本概念

    //

    //  Created by apple on 14-3-18.

    //  Copyright (c) 2014年 apple. All rights reserved.

    //

    #import "Chief.h"

    @implementation Chief

    - (void)dealloc

    {

        [super dealloc];

        NSLog(@"厨师被回收了");

    }

    + (Chief *)chief

    {

        /*

        Chief * chi = nil;

        

        chi = [[Chief alloc] init];

        

    //    [chi release];

        [chi autorelease];

        */

        

        Chief * chi = [[self alloc] init];

        

        

        return [chi autorelease];

    }

    - (Food *)chiefMakeFood

    {

       

      

        //如果在方法中创建一个对象,最好给我初始化为nil,防止出现野指针错误

        // 1

        Food * food = [[Food alloc] init];

        food.name = @"凑豆乳";

    //    // 0

    //    [food release];

        [food autorelease];

        

        return food;

        

    }

    @end

  • 相关阅读:
    POJ 3080 Blue Jeans
    POJ 1961 Period
    POJ 2185 Milking Grid
    POJ 2752 Seek the Name, Seek the Fame
    斗地主算法的设计与实现--项目介绍&如何定义和构造一张牌
    MyEclipse 免安装版制作
    网络子系统48_ip协议数据帧的发送
    Oracle sql语句执行顺序
    当OOP语言RAII特性发展到functional形式的极致
    FusionCharts属性大全
  • 原文地址:https://www.cnblogs.com/supper-Ho/p/6168729.html
Copyright © 2011-2022 走看看