I don't know why my gaze freezes

I have a big problem since a few days I can not solve.

First I have a login 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 that, 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 MMAccountViewController layer, loaded from the MMMainViewController, is the main view controller in which there is nothing.


Now the problem is that sometimes when I load my tabbed controller and I return to the login controller, the screen freezes and a message appears with the message (NSZombieEnabled = YES):

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

That’s all I have, and I really don’t see where I am wrong.

Another idea?

Thanks to those who help me!

+1
source share
2 answers

You re-release something. You might want to run the application in the Tools to check where this can happen (Xcode: Run-> Run With Performance Tool-> Leaks will give you the setting in which you need afaik). I don’t see anything in your code, but you yourself said that you use this code “roughly”, so it cannot be in this part of your program.

Update: I still don’t see that you are overdoing something somewhere ... I am sure that the problem is not in this part of the code. If you have not found a problem yet, you can try to create a test case, that is, a small program that tries to simulate the behavior of these programs and reproduce an error. If you can play it in a small program, I will look at that.

+5
source

I also ran into the same problem, and the problem was that I assigned UIButton to the NavigationItem right and freed up this button instance, I just deleted the release code and started working.

0
source

Source: https://habr.com/ru/post/1315511/


All Articles