NSArray : release its objects, but keep a pointer to it.

Posted by Leo on Stack Overflow See other posts from Stack Overflow or by Leo
Published on 2010-05-17T13:57:44Z Indexed on 2010/05/17 14:00 UTC
Read the original article Hit count: 146

Filed under:
|

Hello, I declare an NSArray in my code then building the array from another array. I process my NSArray and when I'm finished, I would like to release the objects, but I'm reusing this pointer to NSAarray again later to do the same process (creating the array from another array, process then releasing).. So I need to keep the pointer. What should I do ?

Here is roughly what I want to do, the buildArray is creating and returning an autoreleased NSArray :

NSArray *myArray;
for (int i = 0, i < 10, i++){
  [myArray arrayWithArray:[self buildArray]];
  // Here I process myArray
  [myArray = nil] // is my guess
  }

I need to keep a pointer to my NSArray, in order to reuse later in the loop, but what is happening to the objects created with [self buildArray]? What is the best to do in order not to keep unused object and arrays ?

Or maybe the best solution is simply to removeAllObject of the array..?

Thank you!

© Stack Overflow or respective owner

Related posts about nsarray

Related posts about objective-c