- 由于对象间彼此引用,无法释放,所以,循环引用会引发内存泄漏
俩个对象彼此强引用
代码语言:javascript复制#import "Phone.h"
@class AndroidPhone;
@interface iPhone : NSObject
@property (nonatomic,strong) AndroidPhone *phone;
@end
#import "AndroidPhone.h"
@class iPhone;
@interface AndroidPhone : NSObject
@property (nonatomic,strong) iPhone *phone;
@end
- 避免强引用最佳方式就是弱引用 如果指向ObjectA实例的引用移除后,ObjectA会被置为nil
其中一方改为弱引用
代码语言:javascript复制#import "Phone.h"
@class AndroidPhone;
@interface iPhone : NSObject
@property (nonatomic,strong) AndroidPhone *phone;
@end
#import "AndroidPhone.h"
@class iPhone;
@interface AndroidPhone : NSObject
@property (nonatomic,weak) iPhone *phone;
@end