2

仪器显示 100% 的内存泄漏self.window.rootViewController= navigationController;。应用程序使用 ARC。 UINavigationController,UIViewController和 window 都是具有属性 strong 的属性。我该如何解决这个泄漏。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    txnObserver = [[InAppPurchaseObserver alloc] init];
        txnObserver.delegate = self.viewController;
        [[SKPaymentQueue defaultQueue] addTransactionObserver:txnObserver];

    navigationController = [[UINavigationController alloc]initWithRootViewController:viewController];
        **self.window.rootViewController= navigationController;**
        [self.window makeKeyAndVisible];
        return YES;
}

相同的代码在 iOS 6 中没有显示任何泄漏,但在 iOS 7 中显示了泄漏。

2013/10/10 更新了问题的详细信息。

4

1 回答 1

0

您可以didFinishLaunchingWithOptions通过以下代码更改您的,无需 @property of viewController :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

@property (nonatomic, strong) ViewController *viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}
于 2013-10-09T13:07:56.673 回答