Release problem only on quit

  • Hi!

    Here’s my problem:

    I’ve got one window that like in a preferences window loads different
    views managed by subclasses of NSViewController.

    One of those views has an NSTabView that loads different views also
    managed by a subclass of NSViewController, namely TabbedViewController.

    When I switch to another view, the TabbedViewController instance gets
    deallocated, in dealloc I ask it to remove its view from the tabView
    then I send it a release message.

    The problem is that if I just quit the app instead of switching to
    another tab, my app crashes.
    It seems that the app’s terminate process first releases the tabView
    that releases its subview before my controller’s dealloc method gets a
    chance to deallocate. I happen to send a message to an object that
    doesn’t exist anymore.

    Note that the situation was the same before I started using
    NSViewController. I hoped this new class would resolve this issue.
    The only workaround is not to release the controller: it’s safe upon
    quitting but creates a leak when switching.

    What do you think of this? Am I doing things the wrong way?



    PS: This is the same in Apple’s ViewController sample: it is supposed
    to be a document-based app with New and Close commands even if it
    isn’t implemented and there’s no document controller. View controllers
    are allocated and released only when switching from one to another. If
    the doc and windows were closed by the user then the app would keep
    that controller allocated, as a leak…
previous month december 2007 next month
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today