Is Object Releasing on Program Exit Really Needed?

后端 未结 4 492
天命终不由人
天命终不由人 2020-12-31 06:45

Is releasing objects on a programs exit/close needed?

In other words, let us say for the sake of argument, you have a button that closes your application, but right

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 07:05

    On the iPhone, you don't need to, and as far as I am aware, you can't. After receiving applicationWillTerminate: you have a few seconds to save your state and then the OS kills your process. Build one of the sample apps and put a breakpoint in one of the dealloc methods. They never get hit.

    Here is a huge argument about it: link text

    Note: Objective C dealloc is not the same thing as a C++ Deconstructor. In a Deconstructor you can close files, handles, etc. In Objective C dealloc is just for releasing memory. You must close your other resources earlier since dealloc may never get called.

提交回复
热议问题