Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html" rel="nofollow">Memory Management Policy</a> in the "Advanced Memory Management Programming Guide":</p> <blockquote> <p><strong>You own any object you create</strong><br> You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).</p> <p><strong>You must not relinquish ownership of an object you do not own</strong></p> </blockquote> <p>These rules are consistent with methods compiled with ARC. In the <a href="http://clang.llvm.org/docs/AutomaticReferenceCounting.html" rel="nofollow">ARC documentation</a>, the behaviour of methods in the first category is described in "3.2.2. Retained return values":</p> <blockquote> <p>When returning from such a function or method, ARC retains the value at the point of evaluation of the return statement, ...</p> </blockquote> <p>which means that the caller must release the object.</p> <p>Methods in the second category are described in "3.2.3. Unretained return values":</p> <blockquote> <p>When returning from such a function or method, ARC retains the value at the point of evaluation of the return statement, then leaves all local scopes, and then balances out the retain ...</p> </blockquote> <p>which means the the caller must not release the object.</p> <p>So in your example:</p> <pre><code>LibObject* obj1 = [[LibObject alloc] init]; LibObject* obj2 = [obj1 otherObj]; [obj1 release]; //should I release it? --&gt; YES [obj2 release]; //should I release it? --&gt; NO </code></pre> <p>You own <code>obj1</code>, because it was created with <code>alloc</code>, so you have to release <code>obj1</code>.</p> <p>You don't own <code>obj2</code>, therefore you must not release it.</p> <p><em>Note:</em> If you run the Xcode static analyzer on your code, it shows exactly where these rules are violated.</p>
    singulars
    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.
    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