永远不会调用视图控制器的 Dealloc 方法 [英] Viewcontroller Dealloc Method Never Gets Called

查看:38
本文介绍了永远不会调用视图控制器的 Dealloc 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多这样的问题.我都读了.我的问题很简单.

I know there are many questions like this. I read all. My problem is very simple.

我从 xcode 文件>新项目>单视图应用程序创建了一个单视图应用程序.然后我在情节提要中添加了第二个 uiviewcontroller 和一个名为 secondViewController 的新视图控制器类.我将一个按钮拖到主视图控制器,然后通过 ctrl+drag 拖到情节提要上的 secondViewController.我在 secondViewController 中做了相反的事情.并且刚刚将带有 nslog 的 dealloc 函数添加到类文件中.我还添加了对 uibuttons 的弱引用

I created a single view app from xcode file>new project>single view app. Then i added a second uiviewcontroller in storyboard and a new viewcontroller class named secondViewController. I dragged a button to main viewcontroller and by ctrl+drag to secondViewController on storyboard. I did the reverse in secondViewController. And just added dealloc functins with nslog to class files. I also added weak references to uibuttons

当视图改变时,每个视图控制器的Dealloc方法永远不会被调用.

Dealloc method of each viewcontroller never gets called when view changes.

ViewController.m

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"viewDidLoad 1");
        // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    NSLog(@"dealloc 1");
}

SeconViewController.m

SeconViewController.m

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    NSLog(@"dealloc 2");

}
@end

ARC 已启用.

僵尸似乎在产品>编辑方案中被禁用.我正在使用 xcode 6.2.在仪器中,每次切换时分配屏幕内存都会增加.

Zombies seem to be disabled on product>edit scheme. I am using xcode 6.2. In instruments allocation screen memory rises at each toggle.

什么问题,我找不到?

推荐答案

dealloc 在对象(这里是它的视图控制器对象)从内存中滑出时调用.viewwilldisappear 和 diddisappear.

dealloc calls when object's (Here its viewcontroller object) swipe out from memory.But here in your case you must presenting view controllers from one another that leads to call only viewwilldisappear and diddisappear.

在 storyboard 中,如果你想从内存中完全删除这些视图控制器,你应该调用 unwind segue

In storyboard if you want to remove those view controllers completely from memory u should call unwind segue

这篇关于永远不会调用视图控制器的 Dealloc 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆