Xcode 4.3 error message: NSAutoreleasePool is unavailable in main.m

Question: I am trying to create and run a PhoneGap HTML 5 application for iOS 5 but I am getting error message of ‘NSAutoreleasePool is unavailable: not available in automatic reference counting mode’ while building main.m. SDK: Xcode 4.3 Machine: iMAC with Lion. Answer:

You enabled ARC in build settings but your code is not ready to use Automatic Reference Counting. If you use ARC you can’t get to autorelease pools directly. You must use @autoreleasepool blocks instead:

// Old:
int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
    [pool release];
    return retVal;
}

// With ARC replace it with such a code:
int main (int argc, char * argv[]) {
    int retVal;
    @autoreleasepool {
       retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
    }
    return retVal;
}
In your code you can use the followings to be ready to handle both cases:
// For example:
#if __has_feature(objc_arc)
     self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
     self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
#endif
If you don’t want to use ARC, switch it off: 1. Find the Build Settings of your project 2. Search for ‘CLANG_ENABLE_OBJC_ARC’ 3. Set it to NO.