Re: retaining arrays
Re: retaining arrays
- Subject: Re: retaining arrays
- From: Ondra Cada <email@hidden>
- Date: Sat, 22 Sep 2001 23:27:09 +0200
Stephane et all,
>
>>>>> Stephane Sudre (SS) wrote at Fri, 21 Sep 2001 19:49:56 +0200:
SS> it should be (IINTFFTT):
SS>
SS> -(id)initWithArray:(NSArray *)theArray
SS> {
SS>
SS> if ( myPointerToArray!=nil)
SS> {
SS> [myPointer release];
SS> }
SS>
SS> myPointerToArray=[theArray retain]; //myPointerToArray is
SS> } //an instance variable
SS> //if testClass
Almost right. In generic case, though, the proper formula is
-(id)initWithArray:(NSArray *)theArray {
[myPointer autorelease]; //(*)
myPointerToArray=[theArray retain];
}
As for (*), two issues:
(i) No need to check "if (myPointer)", since any message to nil is by
definition an empty operation;
(ii) autorelease is indicated for case when theArray just happens to be the
very same object as myPointer.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc