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

查看:73
本文介绍了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;amp;控制器解除分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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