一些被弃用的UI对象导致iOS8上的内存泄漏



我尝试了导致iOS8.4 SDK内存泄漏的UIAlertView和UIActionSheet对象。来自iOS8的新对象(如UIAlertController)支持最低iOS8操作系统。如何在iOS8和iOS8发布之前处理这个漏洞?

导致泄漏的示例代码段;

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" 
                                                message:@"" 
                                                delegate:self 
                                                cancelButtonTitle:@"OK" 
                                                otherButtonTitles:nil];
[alert show];

我建议检查类的可用性。例如,如果要检查是否使用UIAlertControllerUIAlertView,则:

if ([UIAlertController class]) {
   // use UIAlertController
} else {
  // use UIAlertView
}

最新更新