• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Retain/release question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Retain/release question
      • From: Ricky Sharp <email@hidden>
    • Re: Retain/release question
      • From: Bob Ippolito <email@hidden>
    • Re: Retain/release question
      • From: Jeff Gilbert <email@hidden>
    • Re: Retain/release question
      • From: Will Mason <email@hidden>
  • Prev by Date: Re: [OT] Objective-C history
  • Next by Date: Dates and time zones
  • Previous by thread: NSLayoutManager's replaceTextStorage - slows down the text view?
  • Next by thread: Re: Retain/release question
  • Index(es):
    • Date
    • Thread