Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > awakeFromNib Called Twice

awakeFromNib Called Twice
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Aug 7, 2003, 12:45 AM
 
This is probably a silly question but I'm under the impression that awakeFromNib is only called once and before any other method. However, I have some code were awakeFromNib is being called twice. I'm looking through the code and haven't found the reason. Could it be a memory leak somewhere? Or under what conditions is it called more than once?

In case it helps, the object for which awakeFromNib is being called twice is a subclass of NSView.

Thanks,
(Last edited by DaGuy; Aug 7, 2003 at 12:53 AM. )
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Aug 7, 2003, 01:10 AM
 
do you have two instances of the view?
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Aug 7, 2003, 01:24 AM
 
Originally posted by Uncle Skeleton:
do you have two instances of the view?
Nope just one.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 7, 2003, 01:53 AM
 
Originally posted by DaGuy:
Nope just one.
Are you sure it isn't being instantiated more than once? I mean, have you checked that it is in fact the same object performing the method more than once?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Aug 7, 2003, 01:14 PM
 
Originally posted by Chuckit:
Are you sure it isn't being instantiated more than once? I mean, have you checked that it is in fact the same object performing the method more than once?
I cannot discard that possibility at this point... I'm looking into that.

It could be that the IB instance (or proxy) is out of synch with the rest of the code. I'm looking into that also.

I don't know if this is good practice but comming from a Java background (with garbage collection etc) I usually just alloc objects at abandon then worry about the leaks after I got things to a reasonable working level. Could this practice screw me up big time in the future or is it ok as long as I plug those leaks on the way out? I'm reasoning that all the alloc calls gobble up some memory and there's no danger of overwriting anything since I'm not releasing anything.
(Last edited by DaGuy; Aug 7, 2003 at 01:19 PM. )
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Aug 7, 2003, 01:31 PM
 
I think my Nib is out of sych with the rest of my code... Why? Well, when I make changes in IB, when I get back to PB and try to build, it doesn't prompt me to save changes in the associated Nib file. I had this happen once and I had to create a new project and copy the files over, in order to resolve the situation.

Is there a better way of handling this type of scenario?

     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Aug 7, 2003, 02:07 PM
 
the question is, when you make changes do they appear in your compiled app?

I've had the two get disconnected before I think, and all I had to do was close the nib and open it from within project builder
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 7, 2003, 03:09 PM
 
Originally posted by DaGuy:
I think my Nib is out of sych with the rest of my code... Why? Well, when I make changes in IB, when I get back to PB and try to build, it doesn't prompt me to save changes in the associated Nib file. I had this happen once and I had to create a new project and copy the files over, in order to resolve the situation.

Is there a better way of handling this type of scenario?
I had that problem once. I think I got rid of it by quitting IB, doing a Clean All Targets and then closing and reopening my project. (Don't know if the latter was necessary, but that's what I did, just to be safe.)

Oh, and as for not releasing at first -- unless you have any objects that depend on being destroyed at a certain time, I don't think it should make any immediate difference to your app's behavior. Though I would worry about having to plug all those memory leaks later after I've forgotten where I put them. But I suppose that's just a question of my memory.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Aug 7, 2003, 03:37 PM
 
Another possibility: are you manually loading the nib? That is, are you somewhere calling -[NSBundle loadNibNamed:]? You might want to make sure you're not loading it twice.

Likewise, if your nib is automatically loaded by the NSDocument/NSWindowController architecture, you might want to make sure you're not initing the same NSDocument or NSWindowController instance more than once.

Either of these situations would mean that all the top-level objects in your nib, and perhaps some others, were being leaked.
Rick Roe
icons.cx | weblog
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Aug 7, 2003, 04:56 PM
 
Thanks for your posts. I just found out what the issue was. There were indeed two instances of PlotView (subclass of NSView). How did this happen? Well, I had one instance on the main app window and then (for some reason??) I thought I had to manually instantiate PlotView in IB.

So I had an IB connection going from my controller instance to the PlotView instance. So I got rid of that extra instance and drag a connection from the controller to the PlotView on the main app window (as usual, what was I thinking?). Things worked fine afterwards.

But going back to the original problem, what was really bizarre was that some method calls were received by one instance and other method calls were received by the other. Some black magic I guess...

Anyway, that's all in the past.



I did have that other problem. The Nib was indeed out of synch with the rest of the code. I resolved that, by doing everything that you guys suggested: cleaning targets, restarting IB, restarting PB etc. One of them did the trick, I don't know which...

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2