0
votes

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
A view controller's dealloc is only called when the view controller is dismissed. So your main view controller will never be deallocated. And if you have two view controllers then you do not have a single view app. How can you you didn't touch initial code if you have buttons and two view controllers? Provide relevant details or no one can help you.rmaddy
Fine, but what's the question? If you are leaving this view controller (popping it, or dismissing it) and its dealloc is not called, you have a retain cycle and a memory leak and you need to fix it. If you are not willing to talk about the specific code, what sort of help do you expect here?matt
Sorry i will try my best. I edited the question. @rmaddyRamazan Ayyıldız

1 Answers

1
votes

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