RetainCount2
来源:互联网 发布:linux w3m 使用 编辑:程序博客网 时间:2024/05/29 04:32
新建工程:RetainCount2,修改代码如下:
//// main.m// RetainCount//// Created by cloud on 13-3-8.// Copyright (c) 2013年 cloud. All rights reserved.//#import <Foundation/Foundation.h>@interface RetainTracker:NSObject@end@implementation RetainTracker- (id) init{ if(self=[super init]) { NSLog(@"init: Retain count of %d.",[self retainCount]); } return self;}- (void) dealloc{ NSLog(@"dealloc called.Bye Bye."); [super dealloc];}@endint main(int argc, const char * argv[]){ NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; RetainTracker* tracker=[RetainTracker new]; //count: 1 [tracker retain];//count 2 [tracker autorelease]; [tracker release]; NSLog(@"releasing pool"); [pool release]; return 0;}
运行结果如下:
使用释放池的好外时,你可以在任意地方减少引用记数,但它会在清空释放池时,统一发送release消息。
- RetainCount2
- Shell 编程14(脚本调试技术)
- 九度题目1182:统计单词
- 浅析busybox-1.12.0中ash的脚本命令局限性
- iOS程序之事件处理流程
- "undefined reference to" 问题解决方法
- RetainCount2
- Linux操作系统下的多线程编程详细解析
- yum 更新时,发生错误,解决方法
- ZOJ 2727 List the Books
- shell backgound and base
- 49个jQuery代码经典片段
- 「学习笔记——Python」Python标准库简明教程II
- typename 的两种用法
- delphi XE2开发oxc报DAX error问题