Re: Retain/release question
Re: Retain/release question
- Subject: Re: Retain/release question
- From: Will Mason <email@hidden>
- Date: Fri, 10 Dec 2004 11:15:17 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Since you're creating the array with alloc;init you're also going to
have to releaes it. Just make sure that you have a "release" on your
array somewhere in your code. Remember that anytime you get an object
by alloc or copy you need to release it, because you own it. If you get
an object by a class method, like [NSArray array], then it's
autoreleased and you don't own it. You shouldn't release in that case.
I can't remember the exact location of the docs on this point, but I
guess the idea is that you should only release something that you know
you own, like anything allocated or copied.
Will
--- Bruce Truax <email@hidden> wrote:
> 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
>
_______________________________________________
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