• 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: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")


  • Subject: Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Wed, 18 Feb 2004 17:30:19 -0800

Hello..

It's not anything you (or anyone else) are doing wrong, it's built into the Apple NSDocument code. In order to prevent awakeFromNib from being called the second time, you would probably have to override the Apple provided "save as" mechanism entirely.

As mentioned in the previous thread, the most common reason for this to happen is because awakeFromNib is called on the owner of the nib, and not just the contents of the nib. This behavior is fundamentally necessary, and I doubt Apple will change it, but it does end up causing issues when the same object ends up being used as the owner of multiple nibs, or when an object in a nib is an owner of another nib.

Since there's no way for me to look at the actual code in NSDocument, my guess is that the nib containing the "save as" panel or the nib for the accessory view is being loaded with the NSDocument instance as the owner of the nib, which causes awakeFromNib to be called again on the NSDocument instance since it is the owner.

Even though this specific case in NSDocument should probably be fixed if the above is correct, in general it is better to make sure that anything you do in awakeFromNib does some sort of state check or conditional code to make sure that if awakeFromNib is called multiple times it doesn't break anything (whether you view it as a workaround or good coding practice is up to you).

Louis



On Feb 18, 2004, at 3:40 PM, Ryan Bates wrote:

On Feb 18, 2004, at 1:56 PM, m wrote:
Coincidently, I just got bit by this (awakeFromNib getting called again for instances when doing a "Save As"). Can anybody explain what the rationale for calling awakeFromNib more than once is? I guess more generally, why is the nib being loaded again (or is it) on a "Save As" operation?

Does it still load twice if you comment out everything in the "dataRepresentationOfType:" method and return nil? If not, then try returning an empty data object ( [NSData data] ) and see if that has the same effect. Slowly build up until you find out what's causing it.

Not sure what you're driving at... the second call to awakeFromNib happens just after the save panel is presented but before any saving happens.

It seems to have something to do with loading the "save as" panel, and it only happens the first time you try to "save as", or if your saving and untitled document for the first time.

I can work around it, but it seems wrong, and I'm trying to figure out if I am misunderstanding the intened purpose of awakeFromNib.

_murat
_______________________________________________
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.

  • Follow-Ups:
    • Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
      • From: m <email@hidden>
References: 
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: Rainer Brockerhoff <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: "Louis C. Sacha" <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: Rainer Brockerhoff <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: "Louis C. Sacha" <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: Rainer Brockerhoff <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: "Louis C. Sacha" <email@hidden>)
 >awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking") (From: m <email@hidden>)
 >Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking") (From: Ryan Bates <email@hidden>)
 >Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking") (From: m <email@hidden>)

  • Prev by Date: Re: red black trees
  • Next by Date: Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
  • Previous by thread: Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
  • Next by thread: Re: awakeFromNib called more than once per instance (was Re: static objects "autoreleased with no pool in place - just leaking")
  • Index(es):
    • Date
    • Thread