tags:

views:

63

answers:

2

Let me explain in detais

In appDidfinish()
{
preLoginNavController  = [[PreLoginNavController alloc] initPreLoginNavController];
[window addSubview:[preLoginNavController  view]];
}

then in preLoginViewController when user press a button

then i am doing this to go to view2

RootViewController *arootController= [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
  [self.navigationController pushViewController:arootController animated:YES];

if i do this [arootController release]; then i cant come form view 2

now in view 2 when back button is pressed then i am doing this

[self.navigationController popToRootViewControllerAnimated:YES];

so i cannot release [arootController release] else when i go to back view app quits with no error

and i need a prelogin view before Rootview thats why i did like that now what should i do .. my app is working fine but i want to fix that leak :(

HEY i am getting this message when i click back button in view 2 after push and release in preLogin(1st view) objc[408]: FREED(id): message release sent to freed object=0x466a340

A: 

I think yes, is leaking arootController once you pop it.

nacho4d
A: 

yeah, there will have a leak. 2 suggested solutions are:

[arootController autorelease];

or after you do :

[self.navigationController pushViewController:arootController animated:YES];

you can release it.

A good practice is that : who increase the retain Count, should decrease it. and because aRootController is init in that class, it should be released there

Edit:

This should be the correct code if you want to use navigationController:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    self.preLoginNavController = [[[PreLoginNavController alloc] init] autorelease];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainItemListViewController];
    [window addSubview:[self.navigationController view]];
    [window makeKeyAndVisible];  
}

then when you need to push:

  [self.navigationController pushViewController:anotherViewController animated:YES];
vodkhang
if i release then i am not able to come back from view2 to 1 so i have no options
ram
Why can't you pop back if you release the pushed view controller? What happens when you push, release and then pop?
Michael Kessler
if i pop after release then app just quit
ram
No, if you push then release, then the object is still there, push increase the retain count, right? Then in your view 2, when you are done with all the code, just pop it out:)
vodkhang
How many are viewcontrollers in your navigation controller. Do you know how to catch the exception when it crashed. Your app is crashed, I think so
vodkhang
By the way, why do you push a view controller that is called ROOT view controller? Usually root view controller is first in the navigation controller...
Michael Kessler
@ram: I also suspect something wrong with that. Can you all code in the method. Is it applicationDidFinishLaunching
vodkhang
plz check updates above thanks
ram