Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - viewController dealloc method not called after popping to previous viewController

In iOS, I pop from current viewController into previous one, but it doesn't go into dealloc.

Is this because there is another pointer pointing towards the current viewController, either in a different viewController or in the current one?

This is where I pop to previous view:

- (IBAction)fileUploadCancelTouched:(UIButton *)sender {

    [self.fileToUpload cancel];

    [self.view hideToastActivity];
    [self.greenprogressBar removeFromSuperview];
    [self.subView removeFromSuperview];
    self.fileUploadCancelButton.hidden = YES;
    if (self.commandComeBackToFinalScreen == 1) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

This is my dealloc function:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    self.greenprogressBar = nil;
    self.fileUploadCancelButton = nil;
    self.fileToUpload = nil;
    [buttonHome_ release];
    [buttonTestMeAgain_ release];
    [buttonMarkMyTest_ release];
    [examId_ release];
    [sender_ release];
    self.ob = nil;
    [_fileUploadCancelButton release];
    [super dealloc];
}
like image 501
Operative Avatar asked Apr 30 '14 13:04

Operative


1 Answers

Check to make sure that ARC is not enabled in your project. If it is not ARC enabled then dealloc should be called unless your code is retaining your view controller. You should check through the Instruments tool if your pop commands reduces memory or not.

There may be some other reasons as mentioned in another answer that I am posting below: The obvious reason is that something is retaining your viewController. You will have to look closely at your code. Do you do anything that in your class that uses delegates, since they sometimes retain the delegate. NSURLConnection will retain your class, and so does NSTimer. You can scatter code in you class and log your class's retain count, and try to find out where. In the code you showed so far the retain could should just be 1, since the class is only retained by the navigation controller.

Also, before you pop your view, get a reference to it, pop it with NO animation, and then send it some message that has it report the retain count (this would be some new method you write). That new method could also log other things, like whether it has any timers going, NSURLConnections, etc.

like image 196
Khawar Ali Avatar answered Sep 17 '22 00:09

Khawar Ali