Retain/release question
Retain/release question
- Subject: Retain/release question
- From: Bruce Truax <email@hidden>
- Date: Fri, 10 Dec 2004 11:05:18 -0500
I am still struggling with the retain/release concept. I hope someday to
fully understand it. Most of the time I end up with the correct pairing
because I poke around and look at the retain count and because most times it
does not make much difference. I now have a case where I want to create a 2
dimensional NSArray from a C array of floats and I have upwards of 200,000
elements in the array so I don't want to have a lot of improperly retained
variables. Below I have included the source code to the function which
creates the array. Could someone provide me with the proper retain/release
protocol? Should I set up an autorelease pool for this function?
When I call the function I the calling statement is:
[self setDisplayArray:[self buildArrayFromCArray:outputArray
ofSize:numberOfPoints
withXDimension:xSize
withYDimensiont:ySize]];
When I call this setter function and the display array is released I want to
make sure that all of the row arrays are also released.
- (NSMutableArray *)buildArrayFromCArray:(float*)input
ofSize:(int)nPoints
withXDimension:(int)xDimension
withYDimensiont:(int) yDimension
{
NSMutableArray *theArray;
int column=0;
int row=0;
int i=0;
theArray = [[NSMutableArray alloc] initWithCapacity:xDimension];
for (column = 0; column<xDimension; column++){
NSMutableArray *rowArray = [[NSMutableArray
alloc]initWithCapacity:yDimension];
for (row = 0;row<yDimension; row++){
NSNumber *point = [[NSNumber alloc] initWithFloat:input[i]];
[rowArray addObject:point];
i++;
}
[theArray addObject:rowArray];
}
return theArray;
}
Thanks.
Bruce
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden