Reputation: 7978
I have this code
-(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;
}
}
When I show up the addPrev
the memory increases, when show off the memory does not release.
When the addPrev
dismiss it fires a protocol methos, didCancel
. I intercept it and release addPrev
:
-(void)didCancel
{
[self dismissViewControllerAnimated:YES completion:nil];
addPrev = nil;
}
Upvotes: 1
Views: 1040
Reputation: 7978
Niling also the navigation controller improves drastically the memory allocation. Also, be careful to deallocate what you can deallocate in the dealloc of the pushed controller.
-(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;
navigationController = nil;
}
}
Upvotes: 1