Why is dealloc not called on a brand new project (xcode 3.1.4)?

佐手、 提交于 2020-01-04 11:00:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!