title: Should I retain an autoreleased object when assigned to a retained property?
body: <p>In the getter for one of my retained properties, I allocate and assign an NSArray to my model object("models"). I then sort that NSArray using "sortedArrayUsingSelector:" method. According to the docs, this returns an autoreleased NSArray back. I then reassign that to my "models" array. </p>
  
  <p>At first, I never retained this autoreleased sorted array and found that when I popped this viewController off the stack, my app would crash, saying that I was trying to decrement the reference count on a deallocated object or something of the sort. I then added a retain as you can see in the code below, and all is ok. </p>
  
  <p>My question is, is this correct that I should have to retain the autoreleased object, even though I am retaining this property in its declaration and releasing it in my dealloc?</p>
  
  <pre><code>- (NSArray *)models {
  
      if (!models) {
          models = [[NSArray alloc] initWithArray:[self.modelDictionary allKeys]];
          models = [[models sortedArrayUsingSelector:@selector(compare:)] retain];
      }
      return models;
  </code></pre>
  
  <p>}</p>