20150619_OC之ARC与MRC混合编程
2015-07-03 09:07
225 查看
// // main.m // IOS_ObjectiveC_ARC_MRC混合编程 // // Created by Peng Junlong on 15/6/19. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import <Foundation/Foundation.h> #import "Person.h" #import "Dog.h" //************************ //* ARC_MRC混合编程 * //************************ //Dog和person类是之前的MRC编译的(MRC是手动管理内存,我们在使用第三方库的时候,有时很多都是MRC编译的文件,在编译出错时可以使用一下方法) //MRC -->Manual Reference Counting //ARC -->Automatic Reference Counting //一般将MRC编译的文件导入到ARC环境中运行的时候,需将MRC的文件编译器标志改一下, //在Build Phases->Compile Sources->Compiler Flag中添加"-fno-objc-arc",添加时没有双引号 //将ARC放在MRC环境中时添加-fobjc-arc int main(int argc, const char * argv[]) { @autoreleasepool { Person *person = [[Person alloc] init]; Dog *dog = [[Dog alloc] init]; person.dog = dog; } return 0; }
// // Dog.h // IOS150618_ObjectiveC复合类的内存管理_下 // // Created by Peng Junlong on 15/6/18. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import <Foundation/Foundation.h> @interface Dog : NSObject @property (copy,nonatomic)NSString *name; @property (assign,nonatomic)NSInteger age; @end
// // Dog.m // IOS150618_ObjectiveC复合类的内存管理_下 // // Created by Peng Junlong on 15/6/18. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import "Dog.h" @implementation Dog - (void)dealloc { NSLog(@"Dog is release:%@",[self class]); [_name release]; [super dealloc]; } @end
// Person.h // IOS150618_ObjectiveC复合类的内存管理_下 // // Created by Peng Junlong on 15/6/18. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import <Foundation/Foundation.h> #import "Dog.h" @interface Person : NSObject @property (retain,nonatomic)Dog *dog; @end
// Person.m // IOS150618_ObjectiveC复合类的内存管理_下 // // Created by Peng Junlong on 15/6/18. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import "Person.h" @implementation Person - (void)dealloc { NSLog(@"Person is release :%@",[self class]); [_dog release]; [super dealloc]; } @end
相关文章推荐
- C++结构变量数据对齐问题
- C++结构变量数据对齐问题 分类: C/C++ 2015-07-03 09:07 157人阅读 评论(0) 收藏
- 《Java课程实习》日志(周三)
- sizeof和strlen的区别 分类: C/C++ 2015-07-03 09:05 169人阅读 评论(0) 收藏
- PHP面向对象编程之--多态:方法重载与重写
- java总结(之五)-- 类与接口、多态与继承
- 那一“点”事——Java课程实习
- CFileDialog使用总结
- google map api tips
- Qt插件使用的学习笔记
- XAMPP phpmyadmin MYSQL的配置
- JVM垃圾收集相关常用参数
- java对象在堆内存中的分配原则
- Java程序猿的书面采访String3
- qt信号槽 提前析构 崩溃 异步http请求
- Java学习笔记_成员内部类,静态内部类,方法内部类
- 多线程编程4 - GCD
- java异常解析
- lua程序设计下载
- 《JAVA课程设计》实训第四天——《猜猜看》游戏