简体   繁体   中英

Compiler error when trying to use release method

This is slightly confusing for me because I'm reading an Objective-C book from 2009 (it's the only edition my library had) and the author constantly reminds the reader to release memory, but I get an error when I try to use this method. I read up a little about it and I found out that the release method is deprecated, but is there something I need to do instead of the release method to manage memory, or does Objective-C have garbage collection now?

For example:

NSString *s = [[NSString alloc] init];
[s release];

It is not garbage collection but Automatic Reference Counting ( ARC ) at work for you.

To follow the examples in your book, create a new project in Xcode and deselect the option to use ARC.

You have ARC enabled; calls to retain and release are automatically inserted by the compiler. If you want to do the memory management manually, disable ARC in the target's build settings. On OS X, there is also garbage collection but it is deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM