Re: retaining arrays
Re: retaining arrays
- Subject: Re: retaining arrays
- From: Stéphane Sudre <email@hidden>
- Date: Fri, 21 Sep 2001 19:49:56 +0200
On vendredi, septembre 21, 2001, at 07:37 PM, Robert S Goldsmith wrote:
NSMutableArray *temp;
testClass *classInstance;
temp=[NSMutableArray arrayWithCapacity:2];
[temp addObject:@"String 1"];
[temp addObject:@"String 2"];
classInstance=[[testClass alloc] initWithArray:temp];
Then in testClass
-----
-(id)initWithArray:(NSArray *)theArray
{
myPointerToArray=theArray; //myPointerToArray is
//an instance variable
//if testClass
Now I find that this 'eats' the array in main (it seems to send it a
release message or something). To stop a sigsegv error later on (like
if I tried to release the array temp) I have to send temp a retain
message at some point (either in main before it is passed to the init
call of the instance of testClass or in the init method before the
pointer is copied to myPointerToArray).
Why?
because.
it should be (IINTFFTT):
-(id)initWithArray:(NSArray *)theArray
{
if ( myPointerToArray!=nil)
{
[myPointer release];
}
myPointerToArray=[theArray retain]; //myPointerToArray is
} //an instance variable
//if testClass