简体   繁体   中英

iOS memory management ARC in class methods

I have got several classes with class methods. the project is ARC enabled. how does memory management works in in this case? when the objects created inside class methods are released? should it be done manually? I'm kinda confused.

ARC will automatically mark the variables in that object to autorelease, so when your object is released, the objects inside of it are released too.

If you are using ARC you shouldn't worry too much about it, although is good to know how the memory works.

You dont need to worry about that. ARC will also handle the memory management inside your class method. The objects are releases when the current execution completed . You dont need to manually release that objects.

ARC works by adding code at compile time to ensure that objects live as long as necessary, but no longer. Conceptually, it follows the same memory management conventions as manual reference counting (described in Advanced Memory Management Programming Guide) by adding the appropriate memory management calls for you.

In order for the compiler to generate correct code, ARC restricts the methods you can use and how you use toll-free bridging (see “Toll-Free Bridged Types”). ARC also introduces new lifetime qualifiers for object references and declared properties.

ARC is supported in Xcode 4.2 for OS X v10.6 and v10.7 (64-bit applications) and for iOS 4 and iOS 5. Weak references are not supported in OS X v10.6 and iOS 4.

Xcode provides a tool that automates the mechanical parts of the ARC conversion (such as removing retain and release calls) and helps you to fix issues the migrator can't handle automatically (choose Edit > Refactor > Convert to Objective-C ARC). The migration tool converts all files in a project to use ARC. You can also choose to use ARC on a per-file basis if it's more convenient for you to use manual reference counting for some files.

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