• 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
Retain count on controllers instantiated from nibs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Retain count on controllers instantiated from nibs


  • Subject: Retain count on controllers instantiated from nibs
  • From: Greg Hurrell <email@hidden>
  • Date: Tue, 20 May 2003 23:26:29 +0930

I have a basic Cocoa application, with a controller class that is instantiated in the MainMenu.nib.

I notice that when the app is terminated (using [NSApp terminate:self]) that the controller's dealloc method never gets called.

Now, I know from reading the list archives that this is nothing to worry about as the memory all goes back to the system anyway, BUT I am curious if anyone can tell me what it is that is retaining the controller class.

Specifically, I know that only if I send two release messages to my controller class before exiting then the dealloc method gets called; eg:

- (void)applicationWillTerminate:(NSNotification *)aNotification
{
// I know this is "bad form", but...

[self release]; // controller still hanging around...

[self release]; // only now does "dealloc" get called
}

So my theory is that the controller class has a retain count of 2 because:

1. It is retained because it's instantiated in the nib file (and for some reason i don't understand, things instantiated in the nib file don't get sent a balancing release message at termination time... My guess is that the runtime does this to make apps exit more quickly)

2. It is retained again (perhaps) because I have set it as NSApplication's delegate (by dragging a connection from "File's Owner" in the MainMenu.nib to the instance of my class)

Can anyone older and wiser ;-) shed some light on what is actually going on here? As I said above, it's not something that worrys me; I'm just curious to know what's doing the retaining and why it's not sending a balancing release message...

Cheers
Greg
_______________________________________________
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.

  • Prev by Date: Interface Builder Framework docs (or just a clue, please)
  • Next by Date: BOOLs, definition of YES
  • Previous by thread: Re: Interface Builder Framework docs (or just a clue, please)
  • Next by thread: BOOLs, definition of YES
  • Index(es):
    • Date
    • Thread