OC ARC之循环引用问题(代码分析)
//
// main.m
// 03-arc-循环引用
//
// Created by apple on 13-8-11.
// Copyright (c) 2013年 itcast. All rights reserved.
// #import <Foundation/Foundation.h> @class Dog; @interface Person : NSObject @property (nonatomic, strong) Dog *dog; @end #import "Person.h" @implementation Person - (void)dealloc
{
NSLog(@"Person--dealloc");
} @end #import <Foundation/Foundation.h> @class Person; @interface Dog : NSObject @property (nonatomic, weak) Person *person; @end #import "Dog.h" @implementation Dog
- (void)dealloc
{
NSLog(@"Dog--dealloc");
}
@end #import <Foundation/Foundation.h>
#import "Person.h"
#import "Dog.h" /*
当两端循环引用的时候,解决方案:
1> ARC
1端用strong,另1端用weak 2> 非ARC
1端用retain,另1端用assign
*/ int main()
{
Person *p = [[Person alloc] init]; Dog *d = [[Dog alloc] init];
p.dog = d;
d.person = p; return ;
}
OC ARC之循环引用问题(代码分析)的更多相关文章
- OC ARC之基本使用(代码分析)
// // main.m // 01-arc的基本使用 // // Created by apple on 13-8-11. // Copyright (c) 2013年 itcast. All ri ...
- OC MRC之循环引用问题(代码分析)
// // main.m // 07-循环引用 // // Created by apple on 13-8-9. // Copyright (c) 2013年 itcast. All rights ...
- iOS ARC下循环引用的问题 -举例说明strong和weak的区别
strong:适用于OC对象,作用和非ARC中的retain作用相同,它修饰的成员变量为强指针类型weak:适用于OC对象,作用和非ARC中的assign作用相同,修饰的成员变量为弱指针类型assig ...
- OC学习11——循环引用与@class
转载自 OC学习篇之---@class关键字的作用以及#include和#import的区别 一.#import和#include的区别 当我们在代码中使用两次#include的时候会报错:因为#in ...
- OC - ARC(自动引用计数)
1.什么是自动引用计数? 顾明思义,自动引用计数(ARC,Automatic Reference Counting)是指内存管理中对引用采取自动计数的技术. 在OC中采用ARC机制,让编译器来进行内存 ...
- ARC下循环引用的问题
最初 最近在开发应用时碰到使用ASIHttpRequest后在某些机器上发不出请求的问题,项目开启了ARC,代码是这样写的: @implement MainController - (void) fe ...
- 解决ARC的循环引用问题
看看下面的程序有什么问题: BNRItem.h @interface BNRItem : NSObject @property (nonatomic, strong) BNRItem *contain ...
- OC MRC之 @property参数(代码分析)
第一部分 // // main.m // 04-@property参数 // // Created by apple on 13-8-9. // Copyright (c) 2013年 itcast. ...
- OC MRC之autorelease问题(代码分析)
// // main.m // 08-autorelease // // Created by apple on 13-8-9. // Copyright (c) 2013年 itcast. All ...
随机推荐
- SQL学习之Can't connect to MySQL server on localhost (10061)
最近升级 了系统,开机后连接MySQL报错,Can't connect to MySQL server on localhost (10061): 估计是升级系统清除了以前的缓存设置,网上很多方法是命 ...
- Total Difference String
Total Difference Strings 给一个string列表,判断有多少个不同的string,返回个数相同的定义:字符串长度相等并从左到右,或从右往左是同样的字符 abc 和 cba 为视 ...
- phpstorm怎么设置每个function都用那条横线隔开
- Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
- div转svg svg转canvas svg生成图片及图片下载 分享
链接来自:http://blog.csdn.net/u010081689/article/details/50728854
- Python3基础 file open 打开txt文件并打印出全文
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Git 基础 —— 常见使用场景
Git 基础学习系列 Git 基础 -- 安装 配置 别名 对象 Git 基础 -- 常用命令 Git 基础 -- 常见使用场景 Git基础 -- Github 的使用 突然插入 Bugifx 工作, ...
- uboot启动提示Error, wrong i2c adapter 0 max 0 possible后卡住了怎么办
答:这个与i2c驱动有关,应该使能i2c驱动相关的配置项
- P3870 [TJOI2009]开关
思路 重题 代码 #include <iostream> #include <vector> #include <cstdio> #include <cstr ...
- HDU 2571(dp)题解
命运 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...