- (void)main {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Warning goes here
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while (YES) {
NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
[runLoop run];
[subPool drain];
}
[pool drain];
}
I don’t see why this code get such a warning, especially while it has almost exactly same structure as the main function in main.m generated by Xcode itself which does not get the same warning:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
I believe the issue is the
while (YES)statement. Clang is seeing that as an endless loop that you’ll never get outside of, so that the code below that block will never be reached.Just changing it to the following (a
BOOLvariable set toYESoutside of the block) will remove the warning: