title: Can reusing the same NSError object be problematic?
body: <p>I have since changed my implementation to <em>not</em> do this anymore, but I would be interested in knowing if the following could lead to issues - take for example a process that has multiple steps, each involving passing a reference to an NSError object. If you were to reuse this error object each step along the way, would that reference be negatively effected in some way, perhaps leading to some sort of memory management/dealloc crash?</p>
  
  <h1>Example (most of the in-between code has been omitted)</h1>
  
  <pre><code>    NSError *error;
      NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:&amp;error];
  
      if (!data) {
          return error;
      }
  
      NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
      if (!responseData) {
          return error;
      }
  
      NSDictionary *resultDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;error];
  
      if (!resultDictionary) {
          return error;
      }
  </code></pre>
  
  <p>Even though the error is never "used" twice, meaning the error will be nil (it seems) the next time its reference is passed to another method, could the reference be effected in some way at any of the steps along the way?</p>
  
  <p><strong><em>Original code prior to editing in response to jlehr's comments:</em></strong></p>
  
  <pre><code>    NSError *error;
      NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:&amp;error];
  
      if (error) {
          return;
      }
  
      NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  
      if (error) {
          return;
      }
  
      NSDictionary *resultDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;error];
  
      if (error) {
          return;
      }
  </code></pre>
  
  <p>EDIT: To anyone coming to this at a later date, the information jlehr is referring to can be found here:</p>
  
  <blockquote>
    <p>When dealing with errors passed by reference, it’s important to test
    the return value of the method to see whether an error occurred, as
    shown above. Don’t just test to see whether the error pointer was set
    to point to an error.</p>
  </blockquote>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ErrorHandling/ErrorHandling.html" rel="nofollow">https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ErrorHandling/ErrorHandling.html</a></p>