OBJECTIVE-C Basic 3: Memory management continued

Source: Internet
Author: User

1. We talked about the memory management base in OC, and we'll summarize when we should use memory management.
1) When you create an object with new, alloc, copy, you must release the object.

2) When you have an object, you do not need to release it if it is a temporary object, and you must preserve the object and dispose of the object in the Dealloc method when you need to persist the object for a long time.

Garbage collection mechanism in 2.OC

OC2.0 introduced the garbage collection mechanism, that is, after enabling the garbage collection mechanism, we forgot to release the object, OC will help us to release the object, which shows the power of OC than C + +.

The main principle of garbage collection mechanism is to dynamically track objects in the run , check the object's reference technology and clean up, garbage collection only support Mac,ios not support, because the dynamic release during the operation, not applicable to mobile app, so Apple introduced arc to solve the problem. It is important to note that the XCODE6 settings I am using now have no garbage collection mechanism set up.

ARC mechanism in 3.IOS

The ARC (automatic reference counting) mechanism is similar to the garbage collection mechanism, and will help you manage the life cycle of your objects. The difference is that the garbage collection mechanism decides to dispose of objects at runtime, and arc is the compiler that secretly adds the retain and release methods to our code at compile time. We can select the project and convert the project through the menu Edit->refactor->convert to Objective-c arc. ARC works only on ROP objects. Refer to the OC Basics Tutorial Live Apple's Official document Https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC /introduction/introduction.html.

OBJECTIVE-C Basic 3: Memory management continued

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.