UIButton *testButton = [[UIButton alloc] init];
[self.view addSubview:testButton];
testButton.backgroundColor = [UIColor redColor];
[testButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@100);
make.height.equalTo(@100);
make.left.equalTo(self.view.mas_left);
make.top.equalTo(self.view.mas_top);
}];
[testButton bk_addEventHandler:^(id sender) {
[self dismissViewControllerAnimated:YES completion:nil];
} forControlEvents:UIControlEventTouchUpInside];
我在代码中使用了BlocksKit和Masonry。如果使用I BlocksKit,bk_addEventHandler
,则有一个保留周期,我认为这是因为self保留self.view,保留testButton,保留self。但是,当我单独使用Mansonry而没有BlocksKit,并且我在Masonry mas_makeConstraints
中使用强自我时,我发现没有保留周期,因为viewController可以调用dealloc方法。任何人都可以向我解释在砌体中没有保留周期吗?
答案 0 :(得分:5)
这是因为阻止工具包块保留以便以后执行(因此创建,通过引用自我,保留循环),而砌体块现在或多或少被执行然后被扔掉。
同样,当您调用UIView def apply(desc: Desc): Job[_ <: desc.T]
方法时,您永远不必担心保留周期。这是因为一旦你的代码结束,运行循环结束,动画块被执行并丢弃。但是在NSNotification观察器块中对animate...
的引用可能会导致保留周期,因为它只是由系统永久保留,直到您取消注册该通知,同时保留观察者。