1

我是 Xcode 的新手,如果能帮助我消除这种内存泄漏,我将不胜感激。它显示在线:[window addSubview:navcontrol.view]; 下面是我的代码:

#import "ExSignupAppDelegate.h"
#import "SignupTableViewController.h"

@implementation ExSignupAppDelegate

@synthesize window;

@synthesize viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    UINavigationController* navcontrol;
    navcontrol = [[UINavigationController alloc]init];
    SignupTableViewController* signupVC = [[SignupTableViewController alloc]initWithNibName:@"SignupTableViewController" bundle:nil];
    signupVC.title = NSLocalizedString(@"Title Abstract Search", @"");
    [navcontrol pushViewController:signupVC animated:NO];
    [signupVC release];
    [window addSubview:navcontrol.view];

    return YES;
    }

-(void)applicationDidFinishLaunching:(UIApplication *)application
{
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

- (void)dealloc
{

    [window release];
    [viewController release];
    [super dealloc];
}

@end
4

2 回答 2

1

您正在使用 alloc/init 创建 navController,因此您有责任释放它。改变你的线路

navController = [[UINavigationController alloc]init];

navController = [[[UINavigationController alloc]init] autorelease];

这会将您的 navController 扔到稍后发布的自动释放池中。如果您在其他方法中需要 navController,则应将其存储在属性中。

于 2013-04-24T11:02:34.090 回答
0
[window addSubview:navcontrol.view];

应替换为

window.rootViewController = navcontrol; 
于 2013-04-24T09:34:02.643 回答