title: How memory is managed for an object that is created but not assigned to any pointer?
body: <p>This might be a stupid question, but it keeps bothering me.</p>
  
  <p>Say if we have a method that takes an <code>NSString</code> object as its parameter and does something with  the <code>NSString</code> object,</p>
  
  <pre><code>- (void)someMethod:(NSString *)str
  {
      //do something with str
  }
  </code></pre>
  
  <p>Consider this code</p>
  
  <pre><code>[someObject someMethod:[[NSString alloc] initWithFormat:@"Hello World!"]];
  </code></pre>
  
  <p>Since <code>alloc</code> has been used in creating the string as parameter of someMethod, it has to be balanced by <code>release</code> no matter explicitly in pre-ARC environment or implicitly under ARC. But it seems there is no way we can get a pointer to the string as we have never assigned it to any pointer. </p>
  
  <p>So my question is, first, is this way of passing parameter prohibited in writing objective c code? If no, then how objects created this way get released? And finally, does this code lead to memory leak?</p>
  
  <hr>
  
  <p>Just for the record, I understand the above code is written </p>
  
  <pre><code>NSString *string = [[NSString alloc] initWithFormat:@"Hello World!"];
  [someObject someMethod:string];
  // [string release]; depending on ARC or non-ARC
  </code></pre>