Release, retain, autorelease and at, MT, AMT

Source: Internet
Author: User
Release, retain, autorelease in Objective C, coupled with garbage collection, are difficult to fully understand for beginners who are often confused. Since release exists, why autorelease? Is autorelease garbage collection? Let's take a look at the clutch control in the automobile gearbox.

This can be simplified to consider:
I. No garbage collection

Retain/release is the most basic. One is to increase the count, and the other is to reduce the reference count. After an object is created, we only need to release it when appropriate.

Autorelease is generally used in static functions such as stringwithstring for object creation and initialization. It is similar to release. The only difference is that you do not need to manually release the data, there is a robot in the background to help you release.

2. Garbage Collection
Basically, you can forget release and autorelease, but use Retain as appropriate to prevent early recovery by the system.

This reminds me of AT, MT, and AMT in the automotive speed control system. The clutch processing method is as follows:

Mt is a manual file. You need to step on the clutch by yourself, which is equivalent to release.

At is an automatic file with no clutch, which is equivalent to system garbage collection.

AMT is an automatic shift function based on manual shift. It is equivalent to asking a driver to help you step on the clutch. It is equivalent to autorelease. On the surface, you don't have to step on the clutch and release on your own, in fact, some people help you.

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.