博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OC ARC之循环引用问题(代码分析)
阅读量:7056 次
发布时间:2019-06-28

本文共 988 字,大约阅读时间需要 3 分钟。

1 // 2 //  main.m 3 //  03-arc-循环引用 4 // 5 //  Created by apple on 13-8-11. 6 //  Copyright (c) 2013年 itcast. All rights reserved. 7 // 8  9 #import 
10 11 @class Dog;12 13 @interface Person : NSObject14 15 @property (nonatomic, strong) Dog *dog;16 17 @end18 19 #import "Person.h"20 21 @implementation Person22 23 - (void)dealloc24 {25 NSLog(@"Person--dealloc");26 }27 28 @end29 30 31 #import
32 33 @class Person;34 35 @interface Dog : NSObject36 37 @property (nonatomic, weak) Person *person;38 39 @end40 41 #import "Dog.h"42 43 @implementation Dog44 - (void)dealloc45 {46 NSLog(@"Dog--dealloc");47 }48 @end49 50 51 52 #import
53 #import "Person.h"54 #import "Dog.h"55 56 /*57 当两端循环引用的时候,解决方案:58 1> ARC59 1端用strong,另1端用weak60 61 2> 非ARC62 1端用retain,另1端用assign63 */64 65 int main()66 {67 Person *p = [[Person alloc] init];68 69 70 Dog *d = [[Dog alloc] init];71 p.dog = d;72 d.person = p;73 74 return 0;75 }

 

转载地址:http://rbgol.baihongyu.com/

你可能感兴趣的文章
【转】如何过滤 adb logcat 输出
查看>>
9260与SAM-BA连接(转)
查看>>
ffmpeg+ffserver搭建流媒体服务器
查看>>
深入理解JVM内幕[转]
查看>>
pytimechart使用
查看>>
蓝桥杯——分而治之的子集数
查看>>
hdu 5430 Reflect (数学推导题)
查看>>
Cortex-M4 Core Registers
查看>>
Android SDK Manager 更新代理配置
查看>>
Scala 深入浅出实战经典 第79讲:单例深入讲解及单例背后的链式表达式
查看>>
Reveal UI 分析工具分析手机 App
查看>>
扩展Bootstrap Tooltip插件使其可交互
查看>>
iOS多用连接、反向协议、安全
查看>>
Swift - 滚动视图(UIScrollView)的用法
查看>>
Altium Designer 出现错误提示(警告)adding items to hidden net GND/VCC
查看>>
poj 3270(置换 循环)
查看>>
RHCE7 管理I-12归档文件并在Linux系统间复制文件
查看>>
第十四回(一):外战折戟再图雪耻 石路徜徉终是难忘
查看>>
Android中Menu的基本用法
查看>>
接口JSon字符串格式
查看>>