zoukankan      html  css  js  c++  java
  • ARC机制

    //

    //  main.m

    //  03-ARC机制

    //

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

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

    //

    //ARC简单,不用程序员在去管理内存

    //1.强指针 Strong

    //2.弱指针 weak

    //只要有强指针指向一个对象,那么系统就不会回收该对象

    //只要没有强指针指向对象,系统立即回收该对象

    //弱指针不影响,对象被回收

    //默认情况下,所有的指针都是强指针类型

    #import <Foundation/Foundation.h>

    #import "Person.h"

    void test(Person * v)//Person * v =

    {

        v = nil;

    }//

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

    {

            

        /*

            

        Person * p = [[Person alloc] init];

        

    //    p = nil;

        

        Person * p1 = p;

        

        p = nil;

       */

        

        

        Person * p = [[Person alloc] init];

        

        test(p);

        

        p = nil;

       

        NSLog(@"adfasdf");

        /*

        //创建出来就会立即被释放掉,因为没有强指针指向该对象

        __weak Person * p = [[Person alloc] init];

        NSLog(@"adfadf");

        */

        

        /*

        Person * p = [[Person alloc] init];

        

        __weak Person * p1 = p;

        

        p = nil;

        */

        

        

        return 0;

    }

  • 相关阅读:
    搜索专题
    KMP专题
    CSU 1326: The contest(分组背包)
    强连通专题
    MST:Bad Cowtractors(POJ 2377)
    MST:Agri-Net(POJ 1258)
    ShortestPath:Layout(POJ 3169)(差分约束的应用)
    MST:Conscription(POJ 3723)
    MST:Roadblocks(POJ 3255)
    DP:Space Elevator(POJ 2392)
  • 原文地址:https://www.cnblogs.com/supper-Ho/p/6168947.html
Copyright © 2011-2022 走看看