【发布时间】:2018-06-12 20:46:16
【问题描述】:
vc2.h
@interface vc2 : UIViewController
@property (nonatomic, strong) NSDictionary *dict;
@end
vc2.m
- (instancetype)init
{
self = [super init];
if (self) {
self.dict = @{@"self":self};
}
return self;
}
根 VC
- (void)viewDidLoad {
[super viewDidLoad];
vc = [[vc2 alloc]init];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
vc = nil;
}
vc2 strong NSDictionary 属性持有 self 并且我在根 VC 中将 vc2 设置为 nil 但是当我在仪器中检查时 vc2 实例仍然存在。
当我设置weak NSDictionary 属性时,vc2 实例在设置为nil 后被释放,但是 Xcode 给了我这个警告 Assigning dictionary literal to a weak property;赋值后对象会被释放
这个内存管理是怎么回事?
【问题讨论】:
-
尝试将弱自我放入数组中。
标签: ios objective-c swift memory-management memory-leaks