Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes and no. You would end up releasing the string memory but "leaking" the NSAutoreleasePool object into memory by using drain instead of release if you ran this under a garbage collected (not memory managed) environment. This "leak" simply makes the instance of NSAutoreleasePool "unreachable" like any other object with no strong pointers under GC, and the object would be cleaned up the next time GC runs, which could very well be directly after the call to <code>-drain</code>:</p> <blockquote> <p>drain</p> <p>In a garbage collected environment, triggers garbage collection if memory allocated since last collection is greater than the current threshold; otherwise behaves as release. ... In a garbage-collected environment, this method ultimately calls <code>objc_collect_if_needed</code>.</p> </blockquote> <p>Otherwise, it's similar to how <code>-release</code> behaves under non-GC, yes. As others have stated, <code>-release</code> is a no-op under GC, so the only way to make sure the pool functions properly under GC is through <code>-drain</code>, and <code>-drain</code> under non-GC works exactly like <code>-release</code> under non-GC, and arguably communicates its functionality more clearly as well. </p> <p>I should point out that your statement "anything called with new, alloc or init" should not include "init" (but should include "copy"), because "init" doesn't allocate memory, it only sets up the object (constructor fashion). If you received an alloc'd object and your function only called init as such, you would not release it:</p> <pre><code>- (void)func:(NSObject*)allocd_but_not_init { [allocd_but_not_init init]; } </code></pre> <p>That does not consume any more memory than it you already started with (assuming init doesn't instantiate objects, but you're not responsible for those anyway).</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. 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