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 #import10 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 }