//
// main.m
// OC10_数组的内存管理
//
// Created by zhangxueming on 15/6/18.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Dog.h"
int main(
int argc,
const char *
argv[]) {
@autoreleasepool {
Dog *dog1 =
[[Dog alloc] init];
Dog *dog2 =
[[Dog alloc] init];
Dog *dog3 =
[[Dog alloc] init];
Dog *dog4 =
[[Dog alloc] init];
Dog *dog5 =
[[Dog alloc] init];
//往数组中添加对象, 对应对象的retainCount 值+1;
NSLog(
@"dog1 retainCount = %li", dog1.retainCount);
NSMutableArray *dogs =
[[NSMutableArray alloc] init];
[dogs addObject:dog1];//dogs[0]-->dog1
[dogs addObject:dog1];
//dogs[1]-->dog1
NSLog(
@"dog1 retainCount = %li", dog1.retainCount);
[dogs addObject:dog2];//dogs[2]-->dog2
[dogs addObject:dog3];
[dogs addObject:dog4];
[dogs addObject:dog5];
[dog1 release];
[dog2 release];
[dog3 release];
[dog4 release];
[dog5 release];
NSLog(@"dog1 retainCount = %li", dog1.retainCount);
//数组对象release 实际上是对数组中的每个一个元素 release 一次
[dogs release];
//NSLog(@"dog1 retainCount = %li", dog1.retainCount);
}
return 0;
}
转载于:https://www.cnblogs.com/0515offer/p/4586975.html
相关资源:ABB凸轮开关 - OC系列.pdf
转载请注明原文地址: https://win8.8miu.com/read-1541440.html