title: Lifespan of NSString cStringUsingEncoding return value
body: <p>I have an NSTextField and get its contents like so</p>
  
  <pre><code>NSString *s = [textField stringValue]
  </code></pre>
  
  <p>Now I want to convert this NSString to a string that my platform-independent C code can handle. Thus I'm doing:</p>
  
  <pre><code>const char *cstr = [s cStringUsingEncoding:NSISOLatin1StringEncoding];
  </code></pre>
  
  <p>What I don't understand now is how long this "cstr" pointer stays valid. Apple docs for cStringUsingEncoding say:</p>
  
  <blockquote>
    <p>The returned C string is guaranteed to be valid only until either the
    receiver is freed, or until the current memory is emptied, whichever
    occurs first. You should copy the C string or use
    getCString:maxLength:encoding: if it needs to store the C string
    beyond this time.</p>
  </blockquote>
  
  <p>Two questions about this:</p>
  
  <ol>
  <li><p>I suppose the aforementioned "receiver" is the NSString returned by the [textField stringValue]. Since I don't own this NSString how can I tell when this will be freed? Is it safe to assume that this NSString won't be freed before the NSTextField widget will be freed?</p></li>
  <li><p>What does "until the current memory is emptied" mean precisely? I don't understand this at all.</p></li>
  </ol>
  
  <p>Of course, I could just go ahead and make a copy but I'd like to understand how long the string pointer returned by cStringUsingEncoding is valid.</p>
  
  <p>I know there are several similar questions here but none could really answer my question since in my case, the owner of the NSString is the NSTextField widget and I don't know when this widget will release the NSString or if it stays valid for the complete lifespan of the widget itself. </p>