title: Using Instruments Leaks & Object Alloc: Are autoreleased objects counted as leaks?
body: <p>I have an iPhone app that's getting memory warnings and so I'm trying to find leaks, make more efficient use of memory, etc., with the help of Instruments. Amongst other things, I'm trying to take out any autoreleased objects and replace with manual alloc/init/release objects. However, some API calls don't appear to have an 'init' version (see code below). I admittedly have some basic misunderstandings: </p>
  
  <ol>
  <li><p>If I 'call into' the API's and get back essentially autoreleased objects, can these objects show up as leaks in Instruments? It seems that I see this behavior in Instruments. </p></li>
  <li><p>If yes to 2, should I just ignore if there's no 'non-autorelease' alternative and I'm using an API that I need? Also, if this code gets called a lot, should I completely rethink the algor?</p></li>
  </ol>
  
  <p>Here's some utility code from my application that gets called a lot. Basically determines if two dates are meaningfully 'equal'. I've left in the commented out code so you can see the types of improvements I'm going after in my codebase - <strong>this DID reduce the memory leaks when subsequently ran in Instruments</strong> as I started to manually create the NSDate (and release) which helped. However, I still have the date component objects which I believe are leaking...but it's an API call (sorry for the code formatting but I can't seem to improve it on SO):</p>
  
  <pre><code>+ (BOOL)isDayEqualToDay:(NSDate*)date anotherDate:(NSDate*)anotherDate
  {
  
      NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];  
      //NSCalendar *cal;  
      NSDateComponents *componentsFromDate, *componentsFromAnotherDate;   
      NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;    
      //cal = [NSCalendar currentCalendar];
      componentsFromDate = [cal components:unitFlags fromDate:date];
      componentsFromAnotherDate = [cal components:unitFlags fromDate:anotherDate];
  
      BOOL bDatesEqual = ([componentsFromDate year] == [componentsFromAnotherDate year] &amp;&amp; 
                          [componentsFromDate month] == [componentsFromAnotherDate month] &amp;&amp; 
                          [componentsFromDate day] == [componentsFromAnotherDate day]);
  
      [cal release];
  
      return bDatesEqual;
  
      /*
      return (
          [componentsFromDate year] == [componentsFromAnotherDate year] &amp;&amp;
          [componentsFromDate month] == [componentsFromAnotherDate month] &amp;&amp; 
          [componentsFromDate day] == [componentsFromAnotherDate day]
      );*/
  }
  </code></pre>
  
  <p>I think the componentsFromDate and componentsFromAnotherDate are showing up as leaks but there just objects essentially returned from an NSData API call (autoreleased). Not sure what else I could really do to make this more efficient and I'm questioning my understanding of how to best use Instruments. Suggestions?</p>