Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In short, the compiler is smarter than you think ;). These errors mean that you are autoreleasing various objects (NSString, NSDictionary, NSNumber) in a context that did not allocate an NSAutoreleasePool. For example, the main.m file of a project should declare an autorelease pool:</p> <pre><code>int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } </code></pre> <p>In many applications this will be the only pool that is ever allocated. Without this pool you can't autorelease anything, and should you try to autorelease it has no pool to go to so it effectively becomes a leak. Check your main function to make sure you have an NSAutoreleasePool being allocated.</p> <p>There are other situations where you may want to declare another NSAutoreleasePool. The most common situation is when selectors are invoked in a new thread. Every thread must have its own NSAutoreleasePool. For more information on this see the slide 36 of <a href="http://cs193p.stanford.edu/" rel="nofollow noreferrer">Stanford University CS193P</a> Lecture 10:</p> <pre><code>- (void)someAction:(id)sender { // Fire up a new thread [NSThread detachNewThreadSelector:@selector(doWork:) withTarget:self object:someData]; } - (void)doWork:(id)someData { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [someData doLotsOfWork]; // Message back to the main thread [self performSelectorOnMainThread:@selector(allDone:) withObject:[someData result] waitUntilDone:NO]; [pool release]; } </code></pre> <p>Another example is an expensive loop where you are autoreleasing many objects. Rather than letting the main NSAutoreleasePool grow to an enormous size, you will find that creating a new NSAutoreleasePool every N times around the loop will help keep your resource use to a minimum. Some of this code was also borrowed from the lecture slides listed above:</p> <pre><code>int N = 10; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for (int i = 0; i &lt; someLargeNumber; i++) { NSString *string = ...; string = [string lowercaseString]; string = [string stringByAppendingString:...]; NSLog(@“%@”, string); // Release the temporary pool and allocate a new one // every N times around the loop if (i % N == 0) { [pool release]; pool = [[NSAutoreleasePool alloc] init]; } } [pool release]; </code></pre> <p>Perhaps you have some code like this which is not always allocating or releasing the pools as expected. I'm not sure the compiler is smart enough to notice this type of issue though.</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