• 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: Is dealloc called for an object instantiated with IB?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is dealloc called for an object instantiated with IB?


  • Subject: Re: Is dealloc called for an object instantiated with IB?
  • From: John Stiles <email@hidden>
  • Date: Sat, 29 Sep 2007 07:56:23 -0700


On Sep 29, 2007, at 5:46 AM, Finlay Dobbie wrote:

On 29/09/2007, Bob Ueland <email@hidden> wrote:
In Hillegass book chapter 4, there is a class called AppController instantiated with IB. In the file AppController.m there is the following method:

- (void)dealloc
{
    NSLog(@"dealloc");
    [speechSynth release];
    [super dealloc];
}
@end


However when I run the application and quit it, I never see the text "dealloc" appear in the log window. Does this mean that this method is never called?

Correct. There is no point individually freeing the memory for every object at application quit time, because the OS will automatically reclaim all the memory in one big chunk.

That's true, of course, but the counterpoint is that dealloc can be used for more than just strictly freeing memory, and these behaviors will be lost at shutdown time.
For C++ veterans, this can be a rough lesson, because in C++, app shutdown does invoke destructors, and it's very common for a destructor to do much more than simply freeing malloc'ed blocks.
Of course, in ObjC, using dealloc to do interesting things will be frowned on even more in the near future, as garbage collection makes it impossible to know if or when your dealloc will be called. Could be immediately, could be much later, could be never! That's fine—all garbage collection systems are like this—but it does impose another limitation on what you can reasonably do in a dealloc.


If you want to know when your application is quitting, you should use
the applicationWillTerminate: delegate method or
NSApplicationWillTerminate notification.

And then it's your job to manually release the objects you care about getting dealloc called on, or do other special behaviors to get your cleanup code to run.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Is dealloc called for an object instantiated with IB?
      • From: Bill Bumgarner <email@hidden>
References: 
 >Is dealloc called for an object instantiated with IB? (From: Bob Ueland <email@hidden>)
 >Re: Is dealloc called for an object instantiated with IB? (From: "Finlay Dobbie" <email@hidden>)

  • Prev by Date: Re: Setting Breakpoints in XCode - Comically slow
  • Next by Date: Re: Setting Breakpoints in XCode - Comically slow
  • Previous by thread: Re: Is dealloc called for an object instantiated with IB?
  • Next by thread: Re: Is dealloc called for an object instantiated with IB?
  • Index(es):
    • Date
    • Thread