iPhone代表&控制器解除分配? [英] iPhone delegate & controller dealloc?

查看:44
本文介绍了iPhone代表&控制器解除分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩一个简单的iphone应用程序,并决定在控制器和委托的deallocs中放置一个NSLog语句,但是这些都不打印到Xcode控制台上?

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?

//应用程序代理

#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

//视图控制器

#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

加里

推荐答案

这是Cocoa touch运行时的优化.在程序结束时不会进行某些释放,因为整个程序都将退出,并且无论如何它们都将被清除.

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.

这篇关于iPhone代表&amp;控制器解除分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆