Re: static objects "autoreleased with no pool in place - just leaking"
Re: static objects "autoreleased with no pool in place - just leaking"
- Subject: Re: static objects "autoreleased with no pool in place - just leaking"
- From: Rainer Brockerhoff <email@hidden>
- Date: Sat, 14 Feb 2004 00:32:07 -0200
At 19:04 -0500 13/02/2004, Public Look wrote:
>
-awakeFromNib message is sent to all objects within a NIB that respond to the message _AND_ the -awakeFromNib message is sent to the object specified as the "owner" when the NIB is loaded: See + loadNibNamed:owner:.
At 16:24 -0800 13/02/2004, Louis C. Sacha wrote:
>
In theory, it's possible that several different situations could result in awakeFromNib to be called multiple times as a result of your own code, although in practice it may be relatively rare that they occur. The reason it happens is because awakeFromNib is also called on the owner of a nib in addition to the actual archived objects in the nib file. For example:
>
>
(1) An instance of your MyApplicationDelegate class is loaded in the main nib, and recieves an awakeFromNib call when the nib file is first loaded since it is an object in the nib. If your application delegate (or any object instantiated in a nib) loads another nib file with itself as the owner of that second nib file (perhaps because you need to load some resources conditionally depending on whether you are running on 10.2 or 10.3 for example), awakeFromNib is called a second time, since it is called on the owner of the nib file as well as the contents.
>
>
(2) An object loads multiple nibs with itself as the owner. Some would consider this to be a problem with the design of the app, prefering each nib should have a distinct owner which also acts as the controller, but sometimes people have issues with using an MVC design (since it isn't always intuitive, not always quite as easy to apply as it seems, and sometimes forces systems to be far more complex than they need to be...) Anyway, regardless of the reason why the object ends up being the owner of multiple nibs, it happens in peoples' code even though nibs aren't really designed to be used that way, and when it does the awakeFromNib method is called once for each nib that the object is the owner for.
Good point, thanks to you both! And I'm rereading those docs ASAP... for some reason I never ran into that particular case, although I do have cases where my app delegate loads other nibs - usually for the "About" box.
I could have sworn that -awakeFromNib was called when the object itself was loaded, not for the owner also... rather counterintuitive IMHO. Must be a misperception from the days of 10.0.0 and the days of "documentation forthcoming" ;-).
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog:
http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
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.