title: ARC and releasing object created in method
body: <p>I have stumbled upon an issue for which I can't find answer elsewhere. When I am calling a method which returns pointer to an object which is later used and at the end set to nil, it is still allocated in memory (according to Instruments). I'm using XCode 4.6.3 and iOS 6.1. ARC is turned on.</p>
  
  <p>Here is sample code:</p>
  
  <p>ClassA.h</p>
  
  <pre><code>@interface ClassA : NSObject
      -(void)runSomething;
  @end
  </code></pre>
  
  <p>ClassA.m</p>
  
  <pre><code>#import "ClassA.h"
  #import "ClassB.h"
  
  @implementation ClassA
  
  -(void)runSomething {
      int counter = 0;
      while (true) {
          ClassB *instance = [self makeClassBWithNumber:counter];
          NSLog(@"%d", [instance getNumber]);
          [NSThread sleepForTimeInterval:0.01];
          instance = nil;
          counter++;
      }
  }
  
  -(ClassB*) makeClassBWithNumber:(int)number {
      return [[ClassB alloc] initWithNumber:number];
  }
  
  @end
  </code></pre>
  
  <p>ClassB.h</p>
  
  <pre><code>@interface ClassB : NSObject
  @property int number;
      -(id)initWithNumber:(int)number;
      -(int)getNumber;
  @end
  </code></pre>
  
  <p>ClassB.m</p>
  
  <pre><code>#import "ClassB.h"
  
  @implementation ClassB
  
  -(id)initWithNumber:(int)number {
      self = [super init];
      if(self) {
          _number = number;
      }
      return self;
  }
  
  -(int)getNumber {
      return [self number];
  }
  
  @end
  </code></pre>
  
  <p>ClassB is created in view controller and method runSomething is called. This sample code produces that created object (ClassB) is never released from memory. If I change code from </p>
  
  <p><code>ClassB *instance = [self makeClassBWithNumber:counter];</code> </p>
  
  <p>to</p>
  
  <p><code>ClassB *instance = [[ClassB alloc] initWithNumber:counter];</code></p>
  
  <p>created object is properly released in each of loop cycle. What is the reason for such behaviour? I found some old answers here on stackoverflow that <code>makeClassBWithNumber</code> should return result invoking autorelease <code>return [result autorelease]</code>, but this can't be done if ARC is enabled.</p>