gpt4 book ai didi

ios - 我的 iOS 应用程序内存泄漏

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:18 24 4
gpt4 key购买 nike

我目前正在修复导致我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com