Does it make any sense to release ivars in appdele

2019-08-02 11:21发布

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条回答
迷人小祖宗
2楼-- · 2019-08-02 11:57

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!

查看更多
登录 后发表回答