zoukankan      html  css  js  c++  java
  • OC11_自动释放池

    //
    //  Dog.h
    //  OC11_自动释放池
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Dog : NSObject
    
    @property (assign, nonatomic)NSInteger age;
    
    @end
    
    
    
    //
    //  Dog.m
    //  OC11_自动释放池
    //
    //  Created by zhangxueming on 15/6/18.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Dog.h"
    
    @implementation Dog
    
    - (void)dealloc
    {
        NSLog(@"dog is release");
        [super dealloc];
    }
    
    @end
    //
    //  main.m
    //  OC11_自动释放池
    //
    //  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 {
            //自动释放是就是一个数组,自动释放池会将池中所有的对象都release一次
            Dog *xiaoHei = [[Dog alloc] init];
            xiaoHei.age = 12;
            NSLog(@"retainCount = %li", xiaoHei.retainCount);
            
            [xiaoHei autorelease];//将xiaoHei 的拥有权交给了自动释放池
            //[array addobject: xiaoHei];//2
            //[xiaoHei release];//1
            
            NSLog(@"retainCount = %li", xiaoHei.retainCount);//正确
        
            Dog *xiaoBai = [[Dog alloc] init];
            [xiaoBai autorelease];
            
        }
        
        //可以有多个释放池
        @autoreleasepool {
            
            
            
            
        }
        
        
        return 0;
    }
  • 相关阅读:
    数字签名(代码签名)流程
    (转)__cdecl __fastcall与 __stdcall
    装修主材
    ATL 获取flash信息
    Windows结构化异常
    格式化HRESULT获取对应文本
    which type of VS files should be committed into a version control system
    读Windows核心编程-5-作业
    IE WebBrowser事件触发
    Windows 结构化异常
  • 原文地址:https://www.cnblogs.com/0515offer/p/4586976.html
Copyright © 2011-2022 走看看