Why are subviews of an NSView not sent a release message when a Cocoa application terminates?

后端 未结 3 1252
礼貌的吻别
礼貌的吻别 2021-01-02 19:37

The short version:

  1. Why are the subviews of NSView objects not sent a release message when a Cocoa application terminates?
  2. I
3条回答
  •  日久生厌
    2021-01-02 19:44

    It's not just views. It's everything. I don't think even the NSApplication object releases itself.

    In fact, I'm pretty sure (but not 100% certain) that the answer to my question #1 is: "Because releasing subviews is unnecessary when the application is about to terminate."

    I believe so as well.

    If you want to your custom object graph released at quit, have your app delegate own it, and release your other top-level objects in applicationWillTerminate:. As long as you're managing all your ownerships correctly and you release every single top-level custom object from that method, all your custom objects, including views, will die.

    Note: I have not tried mixing this with Core Data. It may or may not be possible to do this to your managed objects. I don't have any first-hand experience with that.

提交回复
热议问题