zoukankan      html  css  js  c++  java
  • OC10_数组的内存管理

    //
    //  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;
    }
  • 相关阅读:
    04-增删改查
    03-编写dao实现类方式
    02-基于注解的入门案例
    .net core api 图片上传与加载
    笔记一、数据库初始化 约定
    .net core MVC中级教程(四)
    .net core MVC中级教程(三)
    Windows 盘符映射
    c# 队列和堆栈
    isValidNode
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586975.html
Copyright © 2011-2022 走看看