views:

107

answers:

1

Best practices aside, if I create an object that is owned by my UIApplicationDelegate class, and stays around the entire time the application runs, is there any real advantage to adding an [object release] statement in the UIApplicationDelegate's dealloc method?

The only time that would be called is when the user is shutting down the application, and I assume the entire memory space used by that application is then freed.

From a best-practices standpoint, sure, it makes sense to add memory-management code consistently throughout the entire application, but I'm curious from an execution perspective if it actually matters?

Note: I'm asking this from an iPhone developer's perspective. I'm not sure if it would be different from a Mac OSX perspective?

+2  A: 

The -dealloc for the app delegate will almost certainly never be called (if it is, you almost certainly have a bug), so it doesn't matter in that sense. That said, in Cocoa development best practices are never aside, and careful consistency in your memory management is the single most effective way to avoid some of the hardest to find bugs. So a little extra code is well worth the trouble. But in this case (and there are many other cases like this case), it won't matter in practice.

Rob Napier
Agreed. Don't cheat in some places just because it doesn't matter.
rpetrich
Thanks, the first half of what you said was the answer I was looking for.
Ken Pespisa