title: What is the benefit of insertObject:atIndex: over replaceObjectAtIndex:withObject: on an NSMutableArray
body: <p>When replacing a value at some index with a new value within an NSMutableArray, the old value is held in memory.  The hack to fix is to initialize a new NSMutableArray before every loop.</p>
  
  <p>Steps to Reproduce:</p>
  
  <pre><code>- (id) init{
      self.overlays = [[NSMutableArray alloc] initWithCapacity: [self.anotherArray count]];
  }
  
  - (void) someOtherMethod{
      for(int i = 0 ; i &lt; self.anotherArray ; i++){
          UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
          [view setBackgroundColor:[UIColor colorWithRed:0 
                                                  green:0 
                                                   blue:0 
                                                  alpha:1]];
          [view setAlpha: .2];
          [self.overlays insertObject:view atIndex: i]
      }
  }
  
  - (void) main{
      for(int i = 0 ; i &lt; 4 ; i++){
          [myObject someOtherMethod];
      }
  }
  </code></pre>
  
  <p>insertObject:atIndex effectively causes a memory leak, because it does not release the old value in the array at that index.</p>
  
  <p>I filed a bug report and Apple responded:</p>
  
  <p>insertObject:atIndex: is behaving as defined.  It is doing an insertion, not a replacement.  If you want replacement, you should instead use -replaceObjectAtIndex:withObject:</p>
  
  <p>How could the insertObject:atIndex: ever be of any benefit, as you always lose the reference to the old object at that index.</p>
  
  <p>Is this simply to avoid fixing the issue as it meets old documentation definitions?</p>