Does the view controller release all of its properties?
I have a BaseViewController which is a subclass of UITabBarController and is setting up my views in this view controller.
-(void)setUpViews
{
FirstController *mainViewController = [[FirstController alloc] initAssignment:delegate.currentAssignment withMutableArray:myArray];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
SecondController *secondViewController = [[SecondController alloc] initWithNibName:@"SecondController" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
self.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController,nil];
firstNavController.tabBarItem.image = [UIImage imageNamed:@"blablabla.png"];
firstNavController.tabBarItem.title = @"Stream";
secondViewController.tabBarItem.image = [UIImage imageNamed:@"blabla.png"];
secondViewController.tabBarItem.title = @"Favourite";
}
Now I have another view controller, I call it ViewHandlerController
, subclass BaseViewController
. in my viewDidLoad
in this viewHandler
, i call setUpViews
which is declared in BaseViewController
. on the first screen of my app, when the login button is clicked, I instantiate ViewHandlerController
and execute my tabcontroller successfully using navigation controllers.
[[[UIApplication sharedApplication].windows objectAtIndex:0] addSubview:viewControllerHandler.view];
In my application. there is an exit button. I am using NSNotificationCenter
to call my logoutMethod which is declared on my first screen. My question is how, in this logoutMethod, how can I free the previously allocated objects to avoid memory pressure, since the user can log in again (logIn - logOut -logIn)? because i am using ARC, sets my ViewController to NIL, do all cleanups?
EDIT: removes my ViewControllerHandler from supervisor and sets it to nil, which also allows its subviews to be freed?
Greetings
source to share
Okay, answer your own question (not ARC) - no, the underlying view controller doesn't release its properties on release. But you must use your properties in the viewDidUnload and / or dealloc methods.
If you are using ARC, you should notice that some actions may save your controller, and in some cases it cannot be deleted. Watch out for methods that take an object for a delegate, they may not use weak references
source to share
Take a look at Apple's article on memory management .
You can just use autorelease
in allocation methods or for (UIView *view in [self.view subviews]) {view release};
in dealloc .
Actually release the opposite operation to save. When you save, you will increase by 1 the number of object instances in the allocated memory. This happens when you call alloc, copy, new, mutableCopy
. If you are using ARC you cannot deallocate objects, memory management is no longer your problem.
source to share