title: iOS: understanding Problem with release an NSString
body: <p>I have following code:</p>
  
  <pre><code>+ (NSDictionary*) JSONRequest: (NSString*)query andWithCredentials:(BOOL)withCredentials
  {
  if (withCredentials)
  {
      NSString *username = [LoginHandler GetUsernameFromNSDefaults];
      NSString *password = [LoginHandler GetPasswordFromNSDefaults];
      NSString *additionalQuery = [NSString stringWithFormat:@"login_username=%@&amp;login_password=%@", username, password];
  
      query = [NSString stringWithFormat:@"%@&amp;%@", query, additionalQuery];
  
      [username release];
      [password release];
      [additionalQuery release]; 
  }
  
  NSURLRequest *request = [NSURLRequest requestWithURL:  
                           [NSURL URLWithString:query]];  
  
  NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  
  NSString *jsonString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
  NSDictionary *results = [jsonString JSONValue];
  return results;
  
  [request release];
  [response release];
  [jsonString release];
  [results release];
  
  }
  </code></pre>
  
  <p>The problem is the Release of the additionalQuery-NSString.
  When I run this code, it ends with an BAD-ACCES-EXCEPTION for the </p>
  
  <pre><code>[additionalQuery release];
  </code></pre>
  
  <p>As soon as I comment this out, the code works fine.</p>
  
  <p>Now, as simple as it is, run my app without this line of code could be fine, but my question is: What do Im wrong?</p>
  
  <p>I generate an NSString in an IF-Clause, then I <em>CAN</em> only release it in the IF-Clause. But why I got a Error there?</p>