Re: Memory Management
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