我目前正在修复导致我的 iPhone 应用程序崩溃过多的内存泄漏...
在 appDelegate 中,我使用以下代码来初始化 tabbarcontroller。这是一个好方法吗,尤其是“homeNavigationController.tabBarItem init”部分? (tabBarController 是一个属性,在 dealloc 方法中释放)。
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
tabBarController = [[UITabBarController alloc] init];
// HomeTab view
HomeTabViewController *home = [[HomeTabViewController alloc] initWithNibName"HomeTabViewController" bundle:nil];
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:home];
[homeNavigationController.tabBarItem initWithTitle:NSLocalizedString(@"home", @"home") image:[UIImage imageNamed"home.png"] tag:1];
[localControllersArray addObject:homeNavigationController];
[homeNavigationController release];
[home release];
// My 3 others controllers
...
// End 3 other controllers
tabBarController.viewControllers = localControllersArray;
tabBarController.selectedIndex = 0;
[self.window addSubview:tabBarController.view];
[localControllersArray release];
[tabBarController setDelegate:self];
[self.window makeKeyAndVisible];
这个
[homeNavigationController.tabBarItem initWithTitle:NSLocalizedString(@"home", @"home") image:[UIImage imageNamed"home.png"] tag:1];
是泄漏。您应该将其更改为:
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"home", @"home") image:[UIImage imageNamed"home.png"] tag:1];
homeNavigationController.tabBarItem = tabBarItem;
[tabBarItem release]; // If you are not using ARC.
关于ios - 我的 iOS 应用程序中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7981007/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |