Re: Memory Management
Re: Memory Management
- Subject: Re: Memory Management
- From: "Mike Vannorsdel" <email@hidden>
- Date: Mon, 6 Aug 2001 10:54:11 -0600
Please see the Allocation and Initialization section of Object Oriented
Programming and the Objective-C Language book that's included with the
developer tools:
"Because an init... method might return an object other than the newly
allocated receiver, or even return nil, it's important that programs use
the value that's returned by the initialization method, not just that
returned by alloc or allocWithZone:. The following code is very
dangerous, since it ignores the return of init.
id anObject = [SomeClass alloc];
[anObject init];
[anObject soemOtherMessage];"
Reading that, you'll learn a lot and get a very good grasp on what
should be done and when.
On Sunday, August 5, 2001, at 06:51 PM, Nat! wrote:
Misleading, because they give the impression that super init... could
return something else but self. But if it would return nil, the code
would crash because of NULL pointer exception when setting ivars later
in the code. It would crash also, if there was a different object
returned, because it would certainly not be of our subclass (see below)
and writing ivars (like myArray) would clobber memory.