title: Instruments memory leak iphone
body: <p>I posted this problem a few days ago but it was very muddled and my question wasnt very clear so I removed it. I've been digging around and the memory leak is still persiting. Hopefully this attempt will be clearer.</p>
  
  <p>First off I've run the static analyzer and it reports no memory leaks.</p>
  
  <p>I then ran Instruments and it pointed to a memory leak at this line of code. As far as I can see there is no memory leak.</p>
  
  <pre><code>featured=[[UILabel alloc]initWithFrame:CGRectMake(130,15, 200, 15)];
      //[featured setFont:[UIFont UIFontboldSystemFontOfSize:20]];
      featured.font = [UIFont boldSystemFontOfSize:20];
      featured.backgroundColor= [UIColor clearColor];
      featured.textColor=[UIColor blackColor];    
      featured.text= @"Featured Promo";
  
  
      [self.view addSubview:featured];
      [featured release];
      featured=nil;
  </code></pre>
  
  <p>If I comment out the above code Instruments reports another memory leak in another block of code where there is no discernible leak.</p>
  
  <pre><code>UIButton   *populartbutton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]];    
  populartbutton.frame = CGRectMake(112, 145, 90, 22); // size and position of button
  [populartbutton setTitle:@"Popular" forState:UIControlStateNormal];
  populartbutton.backgroundColor = [UIColor clearColor];
  populartbutton.adjustsImageWhenHighlighted = YES;   
  [populartbutton addTarget:self action:@selector(getpopular:) 
         forControlEvents:UIControlEventTouchUpInside];
  
  
  [self.view addSubview:populartbutton];
  </code></pre>
  
  <p>Instruments also says</p>
  
  <p>Responsible Library = Core Graphics</p>
  
  <p>Responsible Frame = open_handle_to_dylib_path</p>
  
  <p>This Is the stack trace.</p>
  
  <hr>
  
  <pre><code> 53 Promo start
    52 Promo main /Users/..2/main.m:14
    51 UIKit UIApplicationMain
    50 UIKit -[UIApplication _run]
    49 CoreFoundation CFRunLoopRunInMode
    48 CoreFoundation CFRunLoopRunSpecific
    47 GraphicsServices PurpleEventCallback
    46 UIKit _UIApplicationHandleEvent
    45 UIKit -[UIApplication sendEvent:]
    44 UIKit -[UIApplication handleEvent:withNewEvent:]
    43 UIKit -[UIApplication _reportAppLaunchFinished]
    42 QuartzCore CA::Transaction::commit()
    41 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
    40 QuartzCore CALayerLayoutIfNeeded
    39 QuartzCore -[CALayer layoutSublayers]
    38 UIKit -[UILayoutContainerView layoutSubviews]
    37 UIKit -[UINavigationController _startDeferredTransitionIfNeeded]
    36 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:]
    35 UIKit -[UINavigationController _layoutViewController:]
    34 UIKit -[UINavigationController_computeAndApplyScrollContentInsetDeltaForViewController:]
  
    33 UIKit -[UIViewController contentScrollView]
    32 UIKit -[UIViewController view]
    31 Promo -[FeaturedLevelViewController viewDidLoad] /Users/..s/FeaturedLevelViewController.m:67  // THIS IS MY CLASS WHERE THE CODE SAMPLES ABOVE ARE FROM
  
  
    30 UIKit -[UILabel initWithFrame:]
    29 UIKit -[UILabel _commonInit]
    28 UIKit +[UILabel defaultFont]
    27 UIKit +[UIFont systemFontOfSize:]
    26 GraphicsServices GSFontCreateWithName
    25 CoreGraphics CGFontCreateWithName
    24 CoreGraphics CGFontCreateWithFontName
    23 CoreGraphics CGFontFinderGetDefault
    22 CoreGraphics CGFontGetVTable
    21 libSystem.B.dylib pthread_once
    20 CoreGraphics load_vtable
    19 CoreGraphics load_library
    18 CoreGraphics CGLibraryLoadFunction
    17 CoreGraphics load_function
    16 CoreGraphics open_handle_to_dylib_path
    15 libSystem.B.dylib dlopen
    14 dyld dlopen
    13 dyld dyld::link(ImageLoader*, bool, ImageLoader::RPathChain const&amp;)
  
    12 dyld ImageLoader::link(ImageLoader::LinkContext const&amp;, bool, bool, ImageLoader::RPathChain const&amp;)
  
  
    11 dyld ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&amp;, bool, ImageLoader::RPathChain const&amp;)
  
  
    10 dyld dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*)
  
  
     9 dyld dyld::load(char const*, dyld::LoadContext const&amp;)
  
     8 dyld dyld::loadPhase0(char const*, dyld::LoadContext const&amp;, std::vector&lt;char const*, std::allocator&lt;char const*&gt; &gt;*)
  
  
     7 dyld dyld::loadPhase1(char const*, dyld::LoadContext const&amp;, std::vector&lt;char const*, std::allocator&lt;char const*&gt; &gt;*)
  
  
     6 dyld dyld::loadPhase3(char const*, dyld::LoadContext const&amp;, std::vector&lt;char const*, std::allocator&lt;char const*&gt; &gt;*)
  
     5 dyld dyld::loadPhase4(char const*, dyld::LoadContext const&amp;, std::vector&lt;char const*, std::allocator&lt;char const*&gt; &gt;*)
  
     4 dyld dyld::loadPhase5(char const*, dyld::LoadContext const&amp;, std::vector&lt;char const*, std::allocator&lt;char const*&gt; &gt;*)
  
  
     3 dyld dyld::mkstringf(char const*, ...)
     2 dyld strdup
     1 dyld malloc
     0 libSystem.B.dylib malloc
  </code></pre>
  
  <p>I'm really not too sure how to use this information to fix the problem so any guidance would be appreciated. Perhaps the answer is in the trace but I just don't know what to look for?</p>
  
  <p>EDIT::</p>
  
  <p>The above stack trace is when running on the simulator. The following is from running on a device. This trace does not point to any of my own classes</p>
  
  <pre><code> 23 Promo 0x0
    22 libSystem.B.dylib _pthread_body
    21 Foundation __NSThread__main__
    20 Foundation +[NSThread exit]
    19 libSystem.B.dylib _pthread_exit
    18 libSystem.B.dylib _pthread_tsd_cleanup
    17 QuartzCore CA::Transaction::release_thread(void*)
    16 QuartzCore CA::Transaction::commit()
    15 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
    14 QuartzCore CALayerDisplayIfNeeded
    13 QuartzCore -[CALayer display]
    12 QuartzCore -[CALayer _display]
    11 QuartzCore CABackingStoreUpdate
    10 QuartzCore backing_callback(CGContext*, void*)
     9 QuartzCore -[CALayer drawInContext:]
     8 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:]
     7 UIKit -[UILabel drawRect:]
     6 UIKit -[UILabel drawTextInRect:]
     5 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:]
     4 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:]
     3 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:]
     2 WebCore WKSetCurrentGraphicsContext
     1 WebCore CurrentThreadContext()
     0 libSystem.B.dylib calloc
  </code></pre>
  
  <p>EDIT 2::</p>
  
  <p>I noticed a leak that is reported earlier in the apps life cycle. It is pointed to this code block.</p>
  
  <p>This is x-code generated stuff when you make a project right?</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  int main(int argc, char *argv[]) {
  
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      int retVal = UIApplicationMain(argc, argv, nil, nil);
      [pool release];
      return retVal;
  }
  </code></pre>