title: Objective C when to Alloc and Init Clarification
body: <p>I am looking for some clarification on initializing variables in Objective C.</p>
  
  <p>Say I have a method that returns an array. </p>
  
  <pre><code>-(NSMutableArray *) getArray
  {
      NSMutableArray *arr = [[NSMutableArray alloc]init];  //line A
  
  for(int i = 0; i &lt; 10; i++)
  {
      [arr addObject:@"word"];
  }
  
  return arr;
  }
  </code></pre>
  
  <p>And then I call this method.</p>
  
  <pre><code>NSMutableArray *myArray = [[NSMutableArray alloc]init];  //line B
                  myArray = [self getArray];
  </code></pre>
  
  <p>So should I be allocating memory in both lines A and B, neither, or in just A or just B? The alternative being simply</p>
  
  <pre><code>NSMutableArray *arr;      //replacing line A
  NSMutableArray *myArray;  //replacing line B
  </code></pre>