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

Re: Memory Management


  • Subject: Re: Memory Management
  • From: "John C. Randolph" <email@hidden>
  • Date: Sun, 5 Aug 2001 14:35:50 -0700

On Sunday, August 5, 2001, at 01:41 PM, Mike Vannorsdel wrote:

This is common in custom classes. You can use init as your constructor and dealloc as your destructor. ie:

- (id)init
{
self = [super init]; //initialize the object using the super class's method
myArray = [[NSArray alloc] initWithObjects:@"Hello", @"World", nil]; //init your array
return self; //return your object instance
}

There's another thing you should watch out for, which is that -init might get called more than once. I would alter the above to:

- (id)init
{
if (self = [super init]) //initialize the object using the super class's method
{ // super init worked.
if (myArray || myArray = [[NSArray alloc] initWithObjects:@"Hello", @"World", nil]) //init your array *once*
return self;
}
return nil; // something went wrong.
}

-jcr

I almost had a psychic girlfriend, but she left me before we met. -- Steven Wright


References: 
 >Re: Memory Management (From: "Mike Vannorsdel" <email@hidden>)

  • Prev by Date: Re: Bug in NSFormatter (again)?
  • Next by Date: Re: Memory Management
  • Previous by thread: Re: Memory Management
  • Next by thread: Re: Memory Management
  • Index(es):
    • Date
    • Thread