When should one call unbind:? (in a GC application)

  • For a long time, Apple recommended calling -unbind in a view's -dealloc
    method.  With the introduction of garbage collection, this had to
    change.  The new Apple recommendation became:

    - (void)viewWillMoveToSuperview:(NSView*)newSuperview
    {
      [super viewWillMoveToSuperview:newSuperview];
      if (newSuperview == nil)
      {
      [self unbind:...];
      }
    }

    as documented here:
    <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html#unbinding>

    Apple highly discourages doing work in -finalize, so this seems like a
    good idea.

    However, if you use 10.5's new NSView API:
    - (BOOL)enterFullScreenMode:(NSScreen*)screen
        withOptions:(NSDictionary*)options

    then the unbinding is triggered, because viewWillMoveToSuperview: is
    called with nil.  Obviously, we don't want everything unbound, just
    because we are fullscreen.

    Now I don't know where to call -unbind.  Doing it in -finalize seems
    dangerous, what with Apple discouraging it so much.

    This is <rdar://5497135> BTW.

    Thanks,

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
  • On Oct 31, 2007, at 2:03 PM, Sean McBride wrote:

    > For a long time, Apple recommended calling -unbind in a view's -
    > dealloc
    > method.  With the introduction of garbage collection, this had to
    > change.  The new Apple recommendation became:
    >
    > - (void)viewWillMoveToSuperview:(NSView*)newSuperview
    > {
    > [super viewWillMoveToSuperview:newSuperview];
    > if (newSuperview == nil)
    > {
    > [self unbind:...];
    > }
    > }
    >
    > as documented here:
    > <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html#unbinding
    > >
    >
    > Apple highly discourages doing work in -finalize, so this seems like a
    > good idea.
    >
    > However, if you use 10.5's new NSView API:
    > - (BOOL)enterFullScreenMode:(NSScreen*)screen
    > withOptions:(NSDictionary*)options
    >
    > then the unbinding is triggered, because viewWillMoveToSuperview: is
    > called with nil.  Obviously, we don't want everything unbound, just
    > because we are fullscreen.
    >
    > Now I don't know where to call -unbind.  Doing it in -finalize seems
    > dangerous, what with Apple discouraging it so much.
    >
    > This is <rdar://5497135> BTW.

    I haven't played around with viewWillMoveToSuperview:, but I do a fair
    amount of work in viewWilMoveToWindow: and viewDidMoveToWindow.
    Perhaps those APIs will give you the proper hook?

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • On 31 Oct 2007, at 19:03, Sean McBride wrote:

    > Now I don't know where to call -unbind.  Doing it in -finalize seems
    > dangerous, what with Apple discouraging it so much.
    >
    > This is <rdar://5497135> BTW.

    Ideally, if you're using GC, you shouldn't need to do this sort of
    thing because whatever is implementing the binding should be using a
    nilling weak reference, and can therefore detect when you go away and
    clean up itself.

    Of course, whether or not that happens in practice I have no idea, but
    I imagine one of Apple's guys will chime in at this point with more
    information.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
  • On Nov 1, 2007, at 3:34 AM, Alastair Houghton wrote:

    >> Now I don't know where to call -unbind.  Doing it in -finalize seems
    >> dangerous, what with Apple discouraging it so much.
    >>
    >> This is <rdar://5497135> BTW.
    >
    > Ideally, if you're using GC, you shouldn't need to do this sort of
    > thing because whatever is implementing the binding should be using a
    > nilling weak reference, and can therefore detect when you go away
    > and clean up itself.
    >
    No, that doesn't happen unfortunately.

    On Oct 31, 2007, at 12:03 PM, Sean McBride wrote:
    > The new Apple recommendation became:
    > [...] as documented here:
    > <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html#unbinding
    > >
    >
    I should point out that my hints page does not constitute "official
    documentation".

    That said, the recommendation is still to use -
    (void)viewWillMoveToSuperview:(NSView*)newSuperview if your view isn't
    going to go to full screen mode.  If it is, you may still have to use
    dealloc/finalize...

    mmalc
  • On Nov 1, 2007, at 1:26 PM, mmalc crawford wrote:

    > That said, the recommendation is still to use - (void)
    > viewWillMoveToSuperview:(NSView*)newSuperview if your view isn't
    > going to go to full screen mode.  If it is, you may still have to
    > use dealloc/finalize...

    What do the frameworks do? In other words, do the framework views
    support being bound and taken in and out of full screen mode?

    Jim
  • On 11/1/07 1:50 PM, Jim Correia said:

    > On Nov 1, 2007, at 1:26 PM, mmalc crawford wrote:
    >
    >> That said, the recommendation is still to use - (void)
    >> viewWillMoveToSuperview:(NSView*)newSuperview if your view isn't
    >> going to go to full screen mode.  If it is, you may still have to
    >> use dealloc/finalize...
    >
    > What do the frameworks do? In other words, do the framework views
    > support being bound and taken in and out of full screen mode?

    Well, I haven't tested them all, but in my GC app, I can make an
    NSOutlineView fullscreen, and its bindings survive exiting fullscreen.
    Knowing how they do it would be great! :)

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
previous month october 2007 next month
MTWTFSS
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 31        
Go to today