Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>From reading the memory management docs in the SDK, I gathered that factory methods (static constructor methods) would typically be retaining the object for me and adding it to the autorelease pool?</p> </blockquote> <p>Yes, you don't have to worry about <em>releasing</em> objects returned from any method, except the <code>alloc</code>, <code>init</code>, <code>new</code>, and <code>copy</code> methods. </p> <blockquote> <p>This would mean I have no need to retain &amp; release an object as long as the pool does not get released before I expect? </p> </blockquote> <p>Yes.</p> <blockquote> <p>(Which should be at the end of the app, for the default autorelease pool in main()? )</p> </blockquote> <p>No. You can only count on the object being around until you return from whichever method or function you're in. Typically, autorelease pools are flushed when control returns back to your run loop.</p> <p>If you want an object instance to survive beyond the current method you must take ownership of it, by calling 'retain'. You are then also responsible for 'releasing' the instance when you no longer need it.</p> <p>In your case, if you want your NSMutableArray to stick around, you need to <code>retain</code> it. Better yet, use <code>[[NSMutableArray alloc] initWithCapacity: ];</code></p> <p>See <a href="http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447" rel="nofollow noreferrer">Practical Memory Management</a></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.
    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