• 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: Beginner Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginner Question


  • Subject: Re: Beginner Question
  • From: Andrew Pinski <email@hidden>
  • Date: Sat, 2 Feb 2002 14:22:38 -0500

On Saturday, February 2, 2002, at 02:08 , James Spencer wrote:

As a newcomer to Cocoa, I'm trying to work through example material in, among other things, Learning Cocoa. In working through the To Do example in Chapter 12, there is code for the initialization of a subclass of NSMatrix, CalendarMatrix, which is simply a 6 X 7 array of button cells. As I said the code is presented for initialization using initWithFrame:frameRect which merely initializes the super class with a prototype cell, set's the tags for the cells and then initializes an instance variable with an NSCalendarDate which it retains.

Now, I thought I was starting to understand Cocoa's memory management conventions but it appears I still have a long way to go. The book tells me "Now that you've seen the initialization code, you should have no problem implementing dealloc for Calendar Matrix." When I read tis I agreed but having taken my shot at the code, I looked at the authors' sample code and I find:

- (void)dealloc {
[selectedDay release];
}

you need to call [super dealloc];


This presents several questions that I'm hoping some kind soul will help me with. I've tried finding the answers on my own in the Cocoa documentation, by searching through the archives of this list (terrible search engine just to add my 10 cents), and by looking through what I could find at the O'Reilly site. (That doesn't mean that the answer isn't right in front of me but I did look before bothering the list with these

1) Does super's dealloc method release the individual cells in the matrix? I would have thought so as it must be retaining them at initialization.

2) If so, and for that matter, even if not, don't we have to make a call to [super dealloc] to give the superclass a chance to get rid of its structures?

3) If NSMatrix' dealloc does NOT release the individual cells, then don't we have to loop through the matrix ourselves with something like:

for (i = 0; i < 6; i++)
{
for (j = 0; j < 7; j++)
{
[[self cellAtRow:i column:j] release];
}
}

4) With regard to the release of selectedDay (the NSCalendarDate) and, assuming that we need to release the individual cells, their release as well, is there a reason to use release in this context rather than autorelease?

Thanks for the help.

Spence

"Badges?? We don't need no stinkin badges!"
_______________________________________________
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.


References: 
 >Beginner Question (From: James Spencer <email@hidden>)

  • Prev by Date: Re: How to use functions of Kernel.framework? (especially Blowfish)
  • Next by Date: Re: How to use functions of Kernel.framework? (especially Blowfish)
  • Previous by thread: Beginner Question
  • Next by thread: Making an image "zoom"
  • Index(es):
    • Date
    • Thread