title: Objective C - autoreleasepool and ARC leak memory
body: <p>In my understanding, if <code>ARC</code> is enabled, objects inside <code>@autoreleasepool{}</code> should be released when they are not used anymore.</p>
  
  <p>However, the code</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  int main(int argc, const char * argv[])
  {
      @autoreleasepool {
          for (int i = 0; i &lt; 1000000000; i++) {
              NSString *string = @"ab c";
              NSArray *array = [string componentsSeparatedByString:string];
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>leaks memory.</p>
  
  <p>Instruments show that leaked objects are __NSArrayM created by -[NSString componentsSeparatedByString:]</p>
  
  <p>So, the question is: why __NSArrayM objects are not being destroyed in the same loop iteration they are created?</p>
  
  <p>Could anyone help me in solving this problem </p>
  
  <p>Update: Thanks for the answers, it seems I used the term "memory leak" incorrectly, and misunderstood how <code>@autoreleasepool{}</code> works. To resolve the problem, I should have placed <code>@autoreleasepool{}</code> inside the for-loop.</p>