Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It did work. You have relinquished ownership of that object, and when the system determines that it is no longer owned, it will be marked available for reuse by the system. That may happen immediately, if you were the only owner of the string. It may happen at some later point, if creation of the string caused it to be autoreleased internally. Or, as Dave DeLong points out, the system may optimize it into an object that is never released.</p> <p>In your case, it's being optimized into a constant string, which will exist for the life of the program. If you were to use an <code>NSMutableString</code> instead of an <code>NSString</code>, you'd see funky behavior that would probably not crash, but wouldn't print what you expected. (See <a href="https://stackoverflow.com/questions/4729906/why-doesnt-this-crash">this question</a> for an example.)</p> <p>If you used an <code>NSArray</code> instead, it <em>would</em> be deallocated when you called <code>release</code>, but you'd still see your NSLog example work correctly until you allocated some other object. Deallocation just marks the memory as available for reuse; it doesn't actually clear it out. So if you passed the array to NSLog, that memory hasn't been changed and thus it still prints correctly.</p> <p>The key point in all of this, though, is to recognize that calling <code>release</code> will not necessarily cause the object to be deallocated. It may continue to exist for any number of reasons. But once you call <code>release</code>, you have relinquished ownership of the object. If you continue using it after that point, the system is free to do all sorts of weird things at its own will, as demonstrated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload