Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>craig is correct when he says you're over-releasing your pool. In a non-GC environment, <code>release</code> and <code>drain</code> have the same effect. In a GC environment, <code>release</code> is a no-op <em>for any object</em>, so <code>drain</code> must be used instead. I'd just use <code>drain</code>.</p> <p>However, <code>NSAutoreleasePool</code> objects aren't really things you should be making a property of your class; they'll work best for you if you restrict their use to a lexical scope. There are a couple of ways you could use a pool in the code you posted above which would be sufficient.</p> <p>Remember when you're spinning your run loop that it's going to be popping in and out of the call to run the run loop in the common modes; so you could do this instead:</p> <pre><code>if (connection != nil) { do { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; [pool drain]; } while (!done); } </code></pre> <p>and you'd be draining any autoreleased objects created in the particular turn of the run loop. Because the connection's delegate callback will be called due to this invocation of the run loop, any autoreleased objects created in the delegate callback will be cleaned up when this pool drains.</p> <p>If you're not comfortable with this, you could place a pool inside your delegate method depending on how much work your delegate method is likely to be doing:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Do whatever work you want here [pool drain]; } </code></pre> <p>And in your case, it would have roughly the same effect.</p> <p>I would strongly recommend doing something like my first example above and eliminating the autorelease pool behavior you have right now. Keeping <code>NSAutoreleasePool</code> objects to a single lexical scope facilitates everything from debugging to safe exception handling when it becomes necessary.</p>
 

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