title: CLLocationManager crashing on release, but why?
body: <p>This might be one of those silly question where, once a solution is pointed out, makes you feel pretty stupid wondering how you didn't see it but I can't figure out why this part of my app is crashing with <strong>EXC_BAD_ACCESS</strong> (and no stack trace).</p>
  
  <p>I have a CLLocationManager *locationManager (ivar declared in interface file) that gets created on <code>viewDidLoad</code> if locationServices is enabled:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      if ([CLLocationManager locationServicesEnabled])
      [self findUserLocation];
      ...
  }
  
  #pragma mark - Location finder methods
  
  - (void)findUserLocation
  {
      locationManager = [[CLLocationManager alloc] init];
      locationManager.delegate = self;
      locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
      [locationManager startUpdatingLocation];    
  }
  </code></pre>
  
  <p>So the location manager starts updating location and each time and update is found, the delegate method below is called, where I check to see if I should time out or continue looking for my desiredAccuracy:</p>
  
  <pre><code>#pragma mark - CLLocationManager delegates
  
  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
  {
      if ([newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp] &gt; 8)
          [self locationManagerTimeOut];
      else if ((newLocation.horizontalAccuracy &lt;= manager.desiredAccuracy) &amp;&amp; (newLocation.verticalAccuracy &lt;= manager.desiredAccuracy))
          [self locationManagerLockedPosition];
  }
  </code></pre>
  
  <p>If a position is locked, this method is called:</p>
  
  <pre><code>- (void)locationManagerLockedPosition
  {
      [locationManager stopUpdatingLocation];
      locationManager.delegate = nil;
      [locationManager release], locationManager = nil;
      NSLog (@"add results to view");
  }
  </code></pre>
  
  <p>If it times out, this is the method called:</p>
  
  <pre><code>- (void)locationManagerTimeOut
  {
      [locationManager stopUpdatingLocation];
      locationManager.delegate = nil;
      [locationManager release], locationManager = nil;
      NSLog (@"Time out!");
  }
  </code></pre>
  
  <p>Problem is, in either case (time out or locked position), I get the NSLog output in the console and then 2 secs later the app crashes?? </p>
  
  <p>Interesting thing is, if I comment out my <code>[locationManager release]...</code> line, everything works fine but WHY? Also if I move the <code>[locationManager release]</code> to my <code>dealloc</code> method, no crashes either!</p>
  
  <p>Am I missing something basic here?</p>
  
  <p>Thanks!</p>
  
  <p>Rog</p>