私のビューには 45 秒近くUIButton
あります。ボタンがメモリに割り当てられていないことはわかっています。何らかの理由でコンパイラがメモリを割り当て/解放しますが、このビューでデバイスが遅くなることに気付きました。UIButton
??でメモリリークを避けるために
ボタンをビューに配置する方法は次のとおりです。
myView.h で:
UIButton *btn1;
myView.m で:
btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setTitle:@"btn1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor = [UIColor clearColor];
btn1.frame = CGRectMake( arc4random() % 920, arc4random() %600+50 , 65, 65);
[self.view addSubview:btn1];
そしてそれを削除する方法:
for(UIButton* b in [self.view subviews]){
[b removeFromSuperview];
b = nil;
}