As you can see in the code below I am creating and initialising a Vertex which I then add into a NSMutableArray instance variable within my Frame object. As I currently have this setup myVert is owned by main and pointed to by vertexList. Would I be better setting this up so that I make a copy of inVertex within the addVertex method so the object takes ownership of its data?
-(void)addVertex:(Vertex*) inVertex {
[vertexList addObject:inVertex];
}
// -------------------
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Frame *myFrame;
Vertex *myVert;
NSLog(@"MDD_ObjectTest ... ");
myFrame = [[Frame alloc] init];
myVert = [[Vertex alloc] initWithxPos:111 yPos:222 zPos:333];
[myFrame addVertex:myVert];
[myVert release];
// Clean up
[myFrame release];
[pool drain];
return 0;
}
Finally if I should make a copy what is the best way to do that, should I be looking at ...
-(void)addVertex:(Vertex*) inVertex {
[vertexList addObject:[inVertex copy]];
}
Although I am a little unsure what to do in terms of the Vertex object with regards to copyWith Zone.
gary