views:

191

answers:

1

Hi there!

I have a big problem since a few days that I can't solve.

First I have a login view controller with this code :

@implementation MMConnectionViewController
@synthesize login, password, activityIndicator, mainVC;


- (BOOL)textFieldShouldReturn:(UITextField *)aTextField 
{
 [aTextField resignFirstResponder];

 [self performSelectorOnMainThread:@selector(startRolling) withObject:nil waitUntilDone:NO];

 [NSThread detachNewThreadSelector:@selector(connect) toTarget:self withObject:nil];

 return YES;
}


- (void)viewWillAppear:(BOOL)flag {
    [super viewWillAppear:flag];
    [login becomeFirstResponder];
 login.keyboardAppearance = UIKeyboardAppearanceAlert;
 password.keyboardAppearance = UIKeyboardAppearanceAlert;
 [self setTitle:@"Monaco Marine"];
 UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout"
                    style:UIBarButtonItemStyleBordered
                   target:nil
                   action:nil];
 self.navigationItem.backBarButtonItem = backBarButtonItem;
 [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
 [backBarButtonItem release];
}

- (void)connect {

 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

 mainVC = [[MMMainViewController alloc] initWithLogin:login.text password:password.text connectPass:@"1" navigationController:self.navigationController nibName:@"MMMainViewController" bundle:nil];


 if (mainVC) {
  [self performSelectorOnMainThread:@selector(dataLoadingFinished) withObject:nil waitUntilDone:YES];
 }

 [pool release];
}

- (void)dataLoadingFinished {
 self.stopRolling;
 [self.navigationController pushViewController:mainVC animated:YES];
}

- (void)showAlertWithMessage:(NSString *)message {
 self.stopRolling;
 NSLog(@"%@",message);
 UIAlertView *warning = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:[NSString stringWithFormat:@"%@",message] delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:nil];
 [warning show];
 [warning release];
}

- (void)startRolling {
 [activityIndicator startAnimating];
}

- (void)stopRolling {
 [activityIndicator stopAnimating];
}


- (void)viewDidLoad {
 [login becomeFirstResponder];
}

- (void)dealloc {
 [login release],login=nil;
 [password release],password=nil;
 [activityIndicator release],activityIndicator=nil;
    [super dealloc];
}

After, there's MMMainViewController with this code :

@implementation MMMainViewController
@synthesize login, password, connectPass, navigationController, accountVC;


- (void)viewDidLoad {

 // Set a title for each view controller. These will also be names of each tab
 accountVC.title = @"Account";

 accountVC.tabBarItem.image = [UIImage imageNamed:@"icon_user.png"];

 self.view.frame = CGRectMake(0, 0, 320, 480);

 // Set each tab to show an appropriate view controller
 [self setViewControllers:
  [NSArray arrayWithObjects:accountVC, nil]];

 [navigationController setNavigationBarHidden:NO animated:NO];

 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Menu"
                   style:UIBarButtonItemStyleBordered
                  target:nil
                  action:nil];
 self.navigationItem.backBarButtonItem = backButton;

 [backButton release];


 [self setTitle:@"Menu"];

}



// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithLogin:(NSString *)l password:(NSString *)p connectPass:(NSString *)c navigationController:(UINavigationController *)navController nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

 UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
 contentView.backgroundColor = [UIColor whiteColor];
 self.view = contentView;
 [contentView release];

 login = l;
 password = p;
 connectPass = c;
 navigationController = navController;

 if (!accountVC)
  accountVC = [MMAccountViewController alloc];

 [self.accountVC
  initWithNibName:@"MMAccountViewController" bundle:nil];

 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 return self;


}

- (void)dealloc {
 [connectPass release];
 [login release];
 [password release];
    [super dealloc];
}

The layer MMAccountViewController loaded from MMMainViewController is a basic view controller with nothing in it.


Now the problem is that sometimes when load my tabbed view controller and I go back to the login view controller, the screen freezes and bug with message (NSZombieEnabled = YES) :

*** -[CALayer retain]: message sent to deallocated instance 0xd0199d0

This is all I have and I really can't see where I'm wrong.

Some more idea?

Thanks for those who help me!

+2  A: 

You are overreleasing something somewhere. You might want to run your application in Instruments to check where it may be happening (XCode: Run->Run With Performance Tool->Leaks will give you the setup that you need afaik). I can't see anything in your code, but you said yourself that you use "roughly" this code, so it may not be in this part of your program.

Update: I still can't see that you overrelease something somewhere... I'm pretty sure the problem is not within this part of the code. If you haven't found the problem yet, you may want to try and create a test case, that is, a small program that tries to mimic this programs behavior and reproduce the bug. If you can reproduce it within a small program, I'll take a look at that.

Nick
Thank you very much for your reply!I will try this. Maybe the problem comes from when the viewcontroller is constructed. I don't have much code in my mainViewController.mI'm going to edit my message with the first viewController.
Romain
My guess is this is directly related to you releasing a view controller where you shouldn't be. As an aside, it is best to not use object names that are the same as Apple's naming, such as here: `self.navigationItem.backBarButtonItem = backBarButtonItem;`
iWasRobbed
@Nick Ok I'll try to make this small program. The problem is that the bug can come randomly. Sometimes it comes after the first push and sometimes later but always on the same view. Is it possible that the simulator or some other outside parameter can change the behavior of my program?@IWasRobbed You're right I haven't paid attention at the name of my objects. I'll make a check on this. Something I'm also not sure : when I have a view controller as an attribute of a class (referencing next view controller), should I release it in my dealloc method or it is managed somewhere else?
Romain
I've made a small test case, I update my main thread to show the code because I can't figure out where the problem is...
Romain
Ok I think I found out why I had this bug. It seems that I'm not loading well my tabBarController (MMMainViewController). I found this tutorial that give me another way to do it : http://www.iphonedevcentral.com/create-uitabbarcontroller/. Thank you very much for your help guys :)
Romain