2010-01-15 3 views
2

나는 간단한 아이폰 앱을 가지고 놀았으며 NSLog 문을 컨트롤러와 델리게이트 모두의 dealloc에 ​​넣기로 결정했으나 Xcode 콘솔로 출력하지 않았다.iPhone 대리자 및 컨트롤러 dealloc?

// 응용 대의원

#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 

게리

답변

5

이것은 Cocoa 터치 런타임에서의 최적화입니다. 특정 프로그램 할당 취소는 프로그램이 끝날 때 완료되지 않습니다. 프로그램 전체가 종료되고 어쨌든 사라지기 때문입니다.

+0

본질적으로 내가 가지고있는 모든 릴리스가 완료되지 않고 있습니다. 정리는 본질적으로 앱이 종료되고 그 풋 프린트가 정리 될 것이라는 사실입니까? – fuzzygoat

+1

이 맞습니다. AppDelegate의 dealloc 메서드는 정상적인 프로그램 작업에서는 호출되지 않습니다. –

0

NSLog (...)에이 문제가 this other stackoverflow question about applicationWillTerminate:

좋은 응답 할 수있다 운.

+0

감사합니다. iPhone_buttonFunAppDelegate에 대한 dealloc (결과적으로 iPhone_buttonFunViewController dealloc)이 applicationWillTerminate 이후에 호출 될 수 있습니다. 이 경우 더 이상의 NSLog가 출력되지 않습니다. – fuzzygoat

+0

그래, deallocs는 그 이후에 일반적으로 온다. 콘솔에 NSLog (...)가 있습니까? – corprew

+0

아니, 시뮬레이터 홈 단추를 누르면 시스템 콘솔에 마지막으로 나타나는 것은 applicationWillTerminate의 NSLog입니다. 이것이 시뮬레이터와 Xcode 사이의 연결이 끊어진 지점이지만, 응용 프로그램을 다시 입력하면 NSLog가 시스템 콘솔로만 이동하지만 여전히 dealloc에서 NSLog가 표시되지 않습니다. – fuzzygoat