-1

In Home ViewController based on user selection I will have to load selected viewcontroller. For this I am changing AppDelegate.window.rootViewController to the navigationcontroller inited with selected view controller.

Ex:

navigationController = [[UINavigationController alloc] initWithViewController:selectedViewController];
[UIApplication delegate].window.rootviewcontroller = navigationController;

This is all working fine but my question here is: from selectedViewController I am navigating to some n no.of viewcontrollers and at last I am loading HomeViewController by setting the appdelegate' rootviewcontroller.

navigationController = [[UINavigationController alloc] initWithViewController:homeViewController];
[UIApplication delegate].window.rootviewcontroller = navigationController;

Will this clear my previous navigationController navigation stack? or should I externally clear the array? Possibly explain me what happens when we assign navigation controller to appdelegate' window rootviewcontroller?

Please note that my application is 6.0 version.

halfer
  • 19,824
  • 17
  • 99
  • 186
Srivathsa
  • 606
  • 10
  • 34
  • 1
    Why would you reset the rootviewcontroller everytime? – Adithya Jun 14 '13 at 10:42
  • Well its existing code which I am not supposed to change. Probably some purpose but here I have to make sure that navigation stack is empty when i change rootviewcontroller. – Srivathsa Jun 14 '13 at 11:52

2 Answers2

1

Navigation stack is maintained by navigation controller. So if you create new navigation controller - its stack is obviously empty. RootViewController property defines who is the main viewController in the current window in the application. So replacing rootviewcontroller will display new controller as main for this window.

Andrei Shender
  • 2,487
  • 22
  • 15
1

No one can guarantee if your code is having memory leaks or not without looking at your code. In general when navigation controller is destroyed, it will release the view controllers on the stack. But sometimes the view controllers could be retained in the code which means they will not be released and will remain active and leak memory.

In your case I will strongly recommend you to profile your app. Use XCode instruments like Allocations/Leaks. Check for the view controller/navigation controller instances whether the memory is getting freed when it is supposed to or not. If memory is getting leaked, find out where in the code the controllers are getting retained.

Here is a good tutorial from Raywenderlich's site on how to find memory leaks in code.

Amar
  • 13,202
  • 7
  • 53
  • 71