应用程序加载时iOS内存泄漏

时间:2012-08-24 07:49:08

标签: iphone objective-c ios memory-leaks

我正在尝试在我的应用上找到内存泄漏。当应用程序加载时,我立即得到一个看起来就像在实验中的内存泄漏

leak

cycles and roots

我该怎么调试呢?只要应用程序加载,无论我运行我的应用程序或我做了多长时间,它都不能重现它。

这是我在委托中的代码

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{   

    tabBarController = [[UITabBarController alloc] init];

    search = [[iPhoneView alloc] initWithNibName:@"iPhoneView" bundle:nil];
    homeNavigationController = [[UINavigationController alloc] initWithRootViewController:search];

    favouritesNavigationController = [[UINavigationController alloc] init];
    favoritesViewController = [[FavoritesViewController alloc]init];
    [favouritesNavigationController pushViewController:favoritesViewController animated:NO];

    aboutUsViewController =[[AboutUsViewController alloc] init];

    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"toolbox" image:[UIImage imageNamed:@"aboutus"] tag:0];
    aboutUsViewController.tabBarItem = item;
    [item release];

    UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"αγαπημένα" image:[UIImage imageNamed:@"favorites"] tag:0];
    favouritesNavigationController.tabBarItem = item2;
    [item2 release];

    NSArray *tabBarControllerCollection = [NSArray arrayWithObjects:homeNavigationController,favouritesNavigationController,aboutUsViewController,nil];
    [tabBarController setViewControllers:tabBarControllerCollection animated:NO];

    [window setRootViewController:tabBarController];
    [tabBarControllerCollection release];   //added that for the leaks

    //[window addSubview:tabBarController.view]; for the warning thing about window and root view controller
    [window makeKeyAndVisible];
}



- (void)dealloc {
    [tabBarController release];
    [search release];
    [favoritesViewController release];
    [favouritesNavigationController release];
    [aboutUsViewController release];
    [window release];
    [super dealloc];
}

2 个答案:

答案 0 :(得分:2)

请使用泄漏的“呼叫树”视图,该视图将显示问题发生的位置并帮助您进行故障排除。同时尝试使用真实设备,因为模拟器可能会显示误报。

Leaks call tree

答案 1 :(得分:1)

释放未发布的 homeNavigationController 并检查您是否在其他地方遗失。