Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, the reason the analyzer is complaining is because you're creating your <code>Hexagram</code> object via <code>alloc] init</code>, and returning it like that, which means your object will start out with a retain count of 1. Unless your method names starts with new/alloc/copy, the user of the code (and static analyzer) will be expecting an autoreleased object. (See <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html" rel="nofollow">documentation of naming conventions + memory management</a>).</p> <p>As for autorelease; Autorelease will give an object a retain count of 1 (so that it can hang around for a bit), but will be released at the end of a run loop. This will cause a retain count of 0, and the object gets deallocated.</p> <p>Now, why does <code>return [current autorelease]</code> fail? The reason will be because of the caller of the method <code>getHexagramforId</code>. If someone is calling a method that returns an autoreleased object (a method that does not start with new/alloc/copy etc...), then it <strong>is their responsibility</strong> to keep hold of that object when it needs to (for the reasons mentioned above).</p> <p>So for example, if you changed <code>return current</code> to <code>return [current autorelease]</code>, and called the method as so:</p> <pre><code>Hexagram* obj = [[SomeClass getHexagramforId:3] retain]; </code></pre> <p>your program shouldn't crash. You are explicitly retaining an autoreleased object, so you now can keep that object around, until you no longer need it. At that point, call <code>[obj release]</code>.</p> <p>Other methods for retaining an autoreleased object include assigning it to a retaining property, as so:</p> <pre><code>@property (nonatomic, retain) Hexagram* hexObj; self.hexObj = [SomeClass getHexagramForId:3]; </code></pre>
    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.
 

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