• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Toplevel Objects in NIB files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Toplevel Objects in NIB files


  • Subject: Re: Toplevel Objects in NIB files
  • From: James DiPalma <email@hidden>
  • Date: Tue, 17 Sep 2002 18:08:19 -0400

I'm glad to see Ondra fighting to get Apple and others to recommend and obey Apple's object ownership rules. I hope someone is listening. As for me, I should not have suggested that it didn't matter if you release NSFontManager; especially since some testing shows that it does matter.

For a practical example, I did this on both 10.1 and 10.2:
In PB, create new document based application
In IB, add an NSMenu and a "Font" menu item to "MyDocument.nib"
Build and run
Close initial window
Open new window

sharedFontManager returns nil (*) resulting in an exception:
Test[] *** -[NSCFArray addObject:]: attempt to insert nil

I demonstrated problems with NSFontManager in a discussion titled "Weird problem with documents SOLVED" here:
http://cocoa.mamasam.com/COCOADEV/2002/07/1/39688.php

Basically, [[NSFontManager alloc] init] does not return an instance with a retain count of +1 and NSWindowController happily releases all top-level objects including a NSFontManager shared instance.

Ondra is right, I hope no one is surprised, Apple should not require us to special case top-level objects that happen to be shared instances. Code that obeys object ownership rules defined in Apple's documentation should have no trouble getting released by NSWindowController.

(*) sharedFontManager returns nil because NSFontManager's dealloc method sets it to nil (which it should do), but subsequent init/sharedFontManager calls do not alloc/init a new instance.


-jim


From: Ondra Cada <email@hidden>

From: Vince DeMarco <email@hidden>

Don't release the Font Manager, its a shared instance in the AppKit. There is only one.

Nevertheless, correct me please if I am wrong, but I believe that it should (and easily could) be fixed by retaining ("overretaining") it when a NIB is loaded, to comply with the general behaviour that all NIB top-level objects are retained (or, more precisely, created and not autoreleased).

I believe such a change would break no backward compatibility, since so far nobody could release it lest the app do weird things; if you add the retain, anyone would be able to consistently release all top-level objects from a NIB as soon as it is needed no more, whilst the fact Font Manager is actually a shared object would be encapsulated under the API level, which I think is the right way to do such things.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Toplevel Objects in NIB files (From: Ondra Cada <email@hidden>)

  • Prev by Date: init code in ApplicationNotifications/awakeFromNib
  • Next by Date: Re: Toplevel Objects in NIB files
  • Previous by thread: Re: Toplevel Objects in NIB files
  • Next by thread: Re: Toplevel Objects in NIB files
  • Index(es):
    • Date
    • Thread