Why do I have to call super -dealloc last, and not first?

后端 未结 6 1116
南旧
南旧 2020-11-27 16:09

correct example:

- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}

wrong example:



        
6条回答
  •  自闭症患者
    2020-11-27 17:00

    Its just a guideline. You can call other instructions after [super dealloc]. however you can not access variables of the superclass anymore because they are released when you call [super dealloc]. It is always safe to call the superclass in the last line.

    Also KVO and depended (triggered) keys can produce side effects if they are depended of already released member variables.

提交回复
热议问题