views:

397

answers:

2

I have been playing with a simple iphone app and decided to put an NSLog statement in the deallocs of both the controller and the delegate but neither of these print out to the Xcode console?

// APPLICATION DELEGATE

#import "iPhone_buttonFunAppDelegate.h"
#import "iPhone_buttonFunViewController.h"

@implementation iPhone_buttonFunAppDelegate

@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {       
    // Override point for customization after app launch
    NSLog(@"applicationDidFinishLaunching ...");
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"AWT:");
}

- (void)dealloc {
    NSLog(@"-DEL-"); // << Does not print?
    [viewController release];
    [window release];
    [super dealloc];
}
@end

// VIEW CONTROLLER

#import "iPhone_buttonFunViewController.h"

@implementation iPhone_buttonFunViewController
@synthesize statusText;

-(IBAction)buttonPressed:(id) sender {
    NSString *title;
    NSString *newText;

    title = [sender titleForState:UIControlStateNormal];
    newText = [[NSString alloc] initWithFormat:@"%@ button pressed.", title];
    [statusText setText:newText];
    [newText release];
    NSLog(@"Button Press ... %@", title);
}

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
    NSLog(@"-1-");
}

-(void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    NSLog(@"-2-");
    self.statusText = nil;
}

-(void)dealloc {
    NSLog(@"-CON-"); // << Does not print?
    [statusText release];
    [super dealloc];
}
@end

gary

A: 
corprew
Thank you, It could be that the dealloc for iPhone_buttonFunAppDelegate (and as a result the iPhone_buttonFunViewController dealloc) are getting called after applicationWillTerminate. In which case no further NSLogs are output.
fuzzygoat
Yeah, the deallocs come after that generally. Does the Console have your NSLog(...)s?
corprew
Nope the last thing that shows up in the system console when you press the simulator home button is the NSLog from applicationWillTerminate. Although this is the point where the connection between the simulator and Xcode is broken, re-entering the app results in NSLogs only going to the system console, but you still don't see the NSLogs from either dealloc.
fuzzygoat
Yeah, If I had to guess they're never actually getting dealloc'd because their refcounts never go to zero and they just get the 'off the end of the tape' treatment.
corprew
+4  A: 

This is an optimization in the Cocoa touch runtime. Certain deallocations aren't made at the end of the program, since the entire program is going to exit and they will be wiped out anyway.

calmh
So essentially all the releases that I have in there aren't getting done either, the cleanup is essentially the fact that the app is quitting and its footprint will be cleanup anyways?
fuzzygoat
correct. The AppDelegate's dealloc method is never called in normal program operation.
Marcus S. Zarra