Object-c------ARC的基本使用
2016-05-05 21:42
507 查看
main.m
Person.h
一端用strong,一端用weak
非ARC
一端用retain,一端用assign
// // main.m // 01-arc的基本使用 // // Created by apple on 13-8-11. // Copyright (c) 2013年 itcast. All rights reserved. // #import <Foundation/Foundation.h> #import "Person.h" #import "Dog.h" /* ARC的判断准则:只要没有强指针指向对象,就会释放对象 1.ARC特点 1> 不允许调用release、retain、retainCount 2> 允许重写dealloc,但是不允许调用[super dealloc] 3> @property的参数 * strong :成员变量是强指针(适用于OC对象类型) * weak :成员变量是弱指针(适用于OC对象类型) * assign : 适用于非OC对象类型 4> 以前的retain改为用strong 指针分2种: 1> 强指针:默认情况下,所有的指针都是强指针 __strong 2> 弱指针:__weak */ int main() { Dog *d = [[Dog alloc] init]; Person *p = [[Person alloc] init]; p.dog = d; d = nil; NSLog(@"%@", p.dog); return 0; } void test() { // 错误写法(没有意义的写法) __weak Person *p = [[Person alloc] init]; NSLog(@"%@", p); NSLog(@"------------"); }
Person.h
/* 作者:MJ 描述: 时间: 文件名:Person.h */ #import <Foundation/Foundation.h> @class Dog; @interface Person : NSObject @property (nonatomic, strong) Dog *dog; @property (nonatomic, strong) NSString *name; @property (nonatomic, assign) int age; @end
ARC循环引用
ARC的循环引用一端用strong,一端用weak
非ARC
一端用retain,一端用assign
相关文章推荐
- Objective-C的appendString,appendFormat 用法
- Android----ObjectAnimator and ValueAnimator
- The type java.lang.Object cannot be resolved It is indirectly referenced ...
- object-oriented first work
- Objective-C method及相关方法分析
- Objective-C学习笔记之获取私有变量的值
- Object-c------autorelease
- Objective-C之run loop详解
- Objective-C:KVC
- Object-c------循环引用
- Objective-C:KVO
- io 流(对象流 objectInputSteam ,objectOutStream)
- objective-C之NSTimer
- Qt QAxObject 操作Excel
- Cannot use object of type PHPExcel_RichText as array
- Objective-C中的Block
- Objective-C面试题(精心整理的,附答案)
- 利用NSUserdefaults来存储自定义的NSObject类及自定义类数组
- objective-C之NSData
- resharper安装后,一不小心点错了(选择了object browser)