集合内存管理

//

//  main.m

//  12-集合内存管理

//

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

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

//

#import <Foundation/Foundation.h>

#import "Person.h"

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

{

    @autoreleasepool {

        

        // retainCount 1

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

        

        //1

        NSMutableArray * array = [[NSMutableArray alloc] initWithCapacity:0];

        

        //当你把对象存入到,数组中的时候,数组会对这个对象进行一次 retain操作

        [array addObject:p];// [p retain] retaiCount 2

        

        //当你把一个对象移除数组中的时候,会对该对象进行一次 release操作 retainCount 1

//        [array removeObject:p];

        //会对数组中所有的对象,进行一次,relsease操作

//        [array removeAllObjects];

        

        //当集合对象被销毁的时候,会对其内部所有的对象进行一次 release操作

        //0

        [array release];

        //retainCount - 0

        

        

        //0

        [p release];

        

        NSLog(@"ddddd");

        

    }

    return 0;

}

原文地址:https://www.cnblogs.com/supper-Ho/p/6185778.html