Dismiss UIViewController不释放内存

时间:2013-10-03 15:04:18

标签: ios memory modalviewcontroller

我有这段代码

 -(void)didPressButton:(int)tag
    {
        // Preventivi?
        if (tag == 0)
        {
            if (addPrev == nil)
                addPrev = [[avvAddPreventivoViewController alloc] init];
            addPrev.delegate = self;
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
            navigationController.navigationBarHidden     = NO;
            [[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
            [self presentViewController:navigationController animated:YES completion:nil];
            addPrev = nil;

        }
    }

当我显示addPrev内存增加时,显示内存时不释放。 当addPrev解雇时会触发协议方法,didCancel。我拦截它并释放addPrev

  -(void)didCancel
    {
        [self dismissViewControllerAnimated:YES completion:nil];
         addPrev = nil;
    }

enter image description here

1 个答案:

答案 0 :(得分:1)

Niling还导航控制器大大改善了内存分配。 另外,请小心释放可以在推送控制器的dealloc中释放的内容。

-(void)didPressButton:(int)tag
    {
        // Preventivi?
        if (tag == 0)
        {
            if (addPrev == nil)
                addPrev = [[avvAddPreventivoViewController alloc] init];
            addPrev.delegate = self;
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
            navigationController.navigationBarHidden     = NO;
            [[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
            [self presentViewController:navigationController animated:YES completion:nil];
            addPrev = nil;
            navigationController = nil;

        }
    }