Viewcontroller Dealloc Method Never Gets Called

这一生的挚爱 提交于 2019-12-12 05:03:57

问题


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

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 method of each viewcontroller never gets called when view changes.

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

#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 is enabled.

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

What is the problem, I couldnt find?


回答1:


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.

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



来源:https://stackoverflow.com/questions/30331710/viewcontroller-dealloc-method-never-gets-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!