平常我们常见的循环引用有block循环引用和对象之间相互强引用两种情况;
1、block循环引用问题:例如
#import "Person.h"
typedef void(^PersonBlock)(NSString *name);
@interface Person()
@property (nonatomic,strong)NSArray *propertyS;
@property (nonatomic,strong)PersonBlock block;
@end
@implementation Person
- (id)init
{
if (self = [super init]) {
self.propertyS = @[@"女", @"23"];
self.block = ^(NSString *name){
NSLog(@"arr:%@", self.propertyS);
};
}
return self;
}
@end
@interface Person : NSObject
{
Person *person1;
Person *person2;
NSArray *array;
}
@property (readwrite,assign)Person *person1;
@property (readonly)Person *person2;
@end
person拥有两个Person对象,每个对象又都拥有一个NSArray对象。属性person1和person2都指向了彼此的Person对象。那么两个对象间形成了强引用,ARC将不会销毁这个对象。