Does it make any sense to release ivars in appdelegate's dealloc?

陌路散爱 提交于 2019-12-13 18:02:15

问题


I know that probably it's a good practice to release appdelegate's ivars in its dealloc method, but practically, does it makes any sence?

As I understand the appdelegate of an iPhone app will live in memory while the application is running and all memory will be freed anyway when it's closed.

Thank you


回答1:


Good memory management should be a habit. The more you have to think about when and where it applies the more likely you are to make mistakes. That may be reason enough alone to do it.

Flip the question around - what do you lose by adding those releases? Is it really much effort to add them?

Some more questions:

  • What happens if the architecture changes a little and the app delegate is released early?
  • What if one of the objects being released does additional clean-up (such as saving out its state) in its dealloc (ignore for a moment whether that's a good idea).
  • Will it generate noise when you Build & Analyze?

Personally I do all my app delegate releases. You could argue that it's not worth it - but I hope I've given you some reasons to consider otherwise.

[update]

I've since blogged about an alternative memory management technique that may be relevant - using (via Objective-C++) smart pointers!



来源:https://stackoverflow.com/questions/3456828/does-it-make-any-sense-to-release-ivars-in-appdelegates-dealloc

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