views:

1124

answers:

2

Apple says, that in Cocoa -dealloc will not be called neccessarily when the application quits. Does this also apply to the iPhone?

+3  A: 

I've used the applicationWillTerminate call to perform releases (or [self release]) which then should allow dealloc to try to clean up nicely

curtisk
you called -dealloc yourself?
Thanks
Swanzus: You should never call dealloc manually!
rpetrich
yeah, sorry, badly worded in my original, the self release *should kick off the dealloc , I'll revise answer
curtisk
+3  A: 

Yes, it does. If the application is quitting, under certain circumstances, dealloc will not be called. If, for example, anything in applicationWillTerminate takes too long or throws an uncaught exception, the application will quit without calling dealloc.

It may be that it never calls dealloc on quit, since the OS does the memory cleanup anyway. The simplest and quickest solution to find out would be to put a breakpoint on the dealloc of your main view controller and see if it's called on application quit.

I think I remember it wasn't called when I tried this once, but I'm not sure, which is why you should try it yourself.

Ed Marty
thanks. well from that perspective, when quitting, the iPhone OS could just free up all that used memory without any care for nicely -dealloc. I guess then it's a bad idea to put other important stuff inside -dealloc.
Thanks
That is correct, it's not a good idea to put anything important inside dealloc. applicationWillTerminate from your application delegate is the proper place to put any important cleanup or save state code.
mmc