Error reported by using nsautoreleasepool in Xcode

Today, when practicing the code on learning Objective-C on MAC, I entered the following code

NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];

//omitted

[pool drain];
return 0;

The error reported by the program is “nsautoreleasepool is unavailable: not available in automatic reference counting mode”

After searching, we know that learning Objective-C on MAC uses the old Xcode version, and arc feature is introduced in the version after xcode4.2 to automatically manage memory, so the following code should be sent as follows

@autoreleasepool{
//omitted.
}

PS: some people on the Internet suggest turning off arc in the settings to continue to use nssautoreleasepool. I wonder why this requirement exists. Is it because the old code is compiled with the new Xcode?If it’s a new project, you’d better try to use arc. After all, how wonderful it is to be able to automatically manage memory

Similar Posts: