title: Non-ARC Project: NSMutableArray, NSString Memory Leak
body: <p>Our company team works on an existing application. That project is non-ARC (automatic reference counting). There is doubt occurs about release the object following code.</p>
  
  <p>Code 1: Why is there no crash when I execute this code?</p>
  
  <pre><code>NSMutableArray *arraytest=[[NSMutableArray alloc]init];
  for(int i=0;i&lt;100;i++)
  {
     NSString *str=[NSString stringWithFormat:@"string:%d",i];
    [arraytest addObject:str];
  }
  NSLog(@"arraytest before:%@",arraytest);
  [arraytest release];
  NSLog(@"arraytest after:%@",arraytest);
  </code></pre>
  
  <p>Similar code: with mutable copy</p>
  
  <p>Code 2: After the changes the following code crashes at the last line.</p>
  
  <pre><code>NSMutableArray *arraytest=[[NSMutableArray alloc]init];
  for(int i=0;i&lt;100;i++)
  {
     NSString *str=[NSString stringWithFormat:@"string:%d",i];
    [arraytest addObject:str];
  }
  NSLog(@"arraytest before:%@",arraytest);
  NSMutableArray *copyarray=[arraytest mutableCopy];
  [arraytest release];
  NSLog(@"copyarray:%@",copyarray);
  NSLog(@"arraytest after:%@",arraytest);
  </code></pre>
  
  <p>Why is there a memory leak in this line?</p>
  
  <p><a href="https://i.stack.imgur.com/bNqmr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bNqmr.png" alt="enter image description here"></a></p>
  
  <p>And why is there a memory leak in this line?</p>
  
  <p><a href="https://i.stack.imgur.com/8gYMu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8gYMu.png" alt="enter image description here"></a></p>
  
  <p>What is the correct method to execute the above code without memory leaks? Our company guys tells autorelease should not be used above code.</p>