问题
I am starting to learn iPhone programming and this should be apparently a very easy question. I work in xcode 3.1.4. Now, when I create a new project of a window-based application and modify dealloc (in the AppDelegate.m file) so that it actually makes a print statement on the console, I actually can not see that statement. So, my question is why?
So that I can avoid obvious answers, the modified dealloc is:
- (void)dealloc {
NSLog(@"Dealloc is called");
[window release];
[super dealloc];
}
Is this strange or not?
Originally I had posted similar questions here, but now I know that the real problem is the one I describe here. Moderators, feel free to delete my other thread. My apologies.
回答1:
The appDelegate won't be deallocated until the application ends, at which point it's too late to see messages on the console.
Also, for any new projects, you should use ARC anyway, which removes the need to call dealloc in a lot of cases.
回答2:
It could be that NSLog is not available when this dealloc is called. The App delegate is the last thing to be deallocated in your project when the program is finished.
回答3:
Its not getting called because your application might be running by then. And when it is called your application might have been terminated. I agree with borrrden's point that appdelegate's dealloc function is the last thing to be called. If you want to understand retai/release, alloc/dealloc, try using xcode 3.2.6 and if you want to use ARC try xcode 4.2 with ios5.
来源:https://stackoverflow.com/questions/10346636/why-is-dealloc-not-called-on-a-brand-new-project-xcode-3-1-4