Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer to pretty much every single one of your questions is yes. Retains and releases will be added to your code to make it right. Specifically, a setter for a <code>strong</code> property will release its current value and retain its new value. Even if you don't use the synthesized accessors and write your own, they'll still have the right behavior. Indeed, under ARC you're not even allowed to call <code>retain</code> or <code>release</code> in your own code.</p> <p>The one point you seem a bit confused on is the following:</p> <blockquote> <p>Can I release the object by assigning the property to nil ? (This might be unsafe if there are other owners.)</p> </blockquote> <p>It's true that when you set the property to nil, <code>release</code> will be called on the object. But remember, that doesn't necessarily mean the object will be deallocated: that only happens if the retain count goes to 0. </p> <p>When we say an object <strong>owns</strong> another object, we usually mean that the object has a strong reference to the other object, so that <code>retain</code> is called upon assignment. As long as the object has at least one other owner at this point, setting the property to <code>nil</code> won't cause it to be deallocated.</p> <p>There's a much easier way to think about all this if you're using ARC. Forget about <code>retain</code> and <code>release</code>, and just think of object ownership. An object will not be deallocated as long as some other object owns it (with a <code>strong</code> reference). And really the only pitfall to keep in mind are cycles: if two objects own each other, then they can't get deallocated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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