title: [CFArray release]: message sent to deallocated instance
body: <p>I'm using the following method in my code:</p>
  
  <pre><code>- (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString *)key ascending:(BOOL)ascending {
  
      NSSortDescriptor *idDescriptor = [[NSSortDescriptor alloc] initWithKey:key ascending:ascending];
  
      NSArray *sortDescriptors = [NSArray arrayWithObject:idDescriptor];
      NSArray *orderArray = [array sortedArrayUsingDescriptors:sortDescriptors];
  
      [idDescriptor release];
  
      NSMutableArray *result = [NSMutableArray arrayWithArray:orderArray];
  
      return result;
  }
  </code></pre>
  
  <p>Is this a well-coded convenience method? As I think, it returns an autoreleased NSMutableArray.</p>
  
  <p>This method is called by another one:</p>
  
  <pre><code>- (id) otherMethod {
  
      NSMutableArray *otherResult = [[[NSMutableArray alloc] initWithCapacity:[otherArray count]] autorelease];
  
     // I add some stuff to otherResult and then...
  
      NSMutableArray *result = [dbUtils newOrderedArray:otherResult ByKey:@"objectId" ascending:NO];
      return result;
  }
  </code></pre>
  
  <p>This method (otherMethod) is called in some view controller where I want to store returned array and release it when deallocating the view controller. However, when [result retain] is called in this view controller (because I need it to be available and I can't allow it to be deallocated) I receive the following error:</p>
  
  <blockquote>
    <p>[CFArray release]: message sent to deallocated instance</p>
  </blockquote>
  
  <p>I've tried to log <code>[result retainCount]</code> just before calling retain and it print "1". I don't understand why an error is thrown when calling retain.</p>
  
  <p>Thank you,</p>
  
  <p>A</p>