I am adding a ViewControllers view as a subView to another ViewController,
Example :
In FirstScreen viewcontroller i do this,
[self.view addSubview:self.secondScreen.view];
And Once i remove it from FirstScreen i do this
[self.secondScreen.view removeFromSuperView];
self.secondScreen=nil;
But While Adding the subView ViewDidLoad method is called but while removeFromSuperView ViewDidUnLoad is not called.
My Question
1) will all my objects in my secondScreen will get deallocated once i set the instance self.secondScreen to nil
2)Is it safe to do like this so that i wont get any leaks or memory warning
Assuming that your app supports from iOS 5.0 onwards, you need to add it as,
Similarly for removing you can use
removeFromParentViewControllerand then remove from superview. Check apple documentation here.ViewDidUnLoadis deprecated from iOS 6.0 onwards and will not get called. Check the documentation here.Regarding your questions,
Once you are done with
self.secondScreenclass, it will start releasing objects inside this class once you set it to nil. If you are using ARC, you dont have to worry much about releasing. OS will take care of those things.Yes, this is fine if you are using ARC. For non-ARC, you need to make sure that you have released all variables properly in this class. Make sure the retain/release are all balanced in that case.