title: NSString EXC_BAD_ACCESS
body: <p>I'm stuck with the following bit of code.</p>
  
  <pre><code>NSString *gridRef = [[NSString alloc] initWithFormat: @"%@", [converter LatLongToOSGrid: latLong]];
  NSLog(@"Grid Ref: %@", gridRef);
  self.answerLabel.text = [[NSString alloc] initWithFormat: @"%@", gridRef];
  </code></pre>
  
  <p>When I log gridRef, it displays the correct result. However, the line setting answerLabel.text causes an EXC_BAD_ACCESS error and the program crashes. IB is connected to the correct label, what is the problem?</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>I've updated the code as follows:</p>
  
  <pre><code>    - (IBAction)convertLatLong {
      NSArray *latLong = [[NSArray alloc] initWithObjects: latTextField.text, longTextField.text, nil];
  
      GridRefsConverter *converter = [[GridRefsConverter alloc] init];
  
      NSString *gridRef = [[NSString alloc] initWithFormat: @"%@", [converter LatLongToOSGrid: latLong]];
      NSLog(@"Grid Ref: %@", gridRef);
      NSLog(@"Label: %@", self.answerLabel.text);
      answerLabel.text = @"Yippy";
      self.answerLabel.text = gridRef;
  
      [gridRef release];
      [converter release];
      [latLong release];
  }
  </code></pre>
  
  <p>answerLabel is initialised through @property @synthesize when the view controller is pushed onto the stack. (I don't know how it gets init'd apart from it's one of the magical things IB does for you. Or so I assume. I've used exactly the same method in other view controllers and have not had this issue.</p>
  
  <hr>
  
  <p>I've found the culprits - the question is, how do I go about releasing them?</p>
  
  <pre><code>NSString *eString = [[NSString alloc] initWithFormat: @"%f", e];
  NSString *nString = [[NSString alloc] initWithFormat: @"%f", n];
  eString = [eString stringByPaddingToLength: (digits/2) withString: @"0" startingAtIndex: 0];
  nString = [nString stringByPaddingToLength: (digits/2) withString: @"0" startingAtIndex: 0];
  NSString *theGridRef = [letterPair stringByAppendingString: eString];
  theGridRef = [theGridRef stringByAppendingString: nString];
  [eString release];
  [nString release];
  
  return theGridRef;
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>NSArray *gridRef = [[NSArray alloc] init];
  gridRef = [gridRef arrayByAddingObject: [NSNumber numberWithDouble: E]];
  gridRef = [gridRef arrayByAddingObject: [NSNumber numberWithDouble: N]];
  gridRef = [gridRef arrayByAddingObject: [NSNumber numberWithInteger: 8]];
  
  NSString *theGridRef = [[NSString alloc] initWithFormat: @"%@", [self gridRefNumberToLetter: gridRef]];
  
  [gridRef release];
  [theGridRef autorelease];
  
  return theGridRef;
  </code></pre>
  
  <p>}</p>