2016-2-Arc Knowledge Summary (two autorelease concepts and implementation)

Source: Internet
Author: User
Tags variable scope

First of all, I wish my happy Birthday ~23 ~

The concept of a autorelease

Autorelease will treat an object instance as if it were a C-language automatic variable. When the scope (equivalent to a variable scope) is exceeded, an instance of the object's release strength method is called.

In addition, unlike the C language automatic variable, the programmer can set the scope of the variables themselves, that is, through the autoreleasepool to achieve.

The Autorelease method of invoking an object is to put the object nearest to a NSAutoreleasePool, the object's lifetime is equivalent to the scope of the C language variable. For all objects that call the Autorelease method, the release method is called when the auto-free pool is destroyed.

A typical application is in the Nsrunloop. When the observe hears the Runloop entry, it creates an auto-release pool that destroys the auto-free pool and re-creates a new auto-release pool before the Runloop enters hibernation. An auto-release pool is also destroyed when Runloop exits this way, you can avoid out-of-memory symptoms.

The other is that many of the class methods in the Cocoa framework also return autorelease objects, such as +array.

Realization of two Autorelease

Learn by GNUstep:

When calling the Autorelease method, internal is actually an instance method that invokes the currently used Autoreleasepool object

[Pool addobject:obj];

The method, in essence, is to add an object to the inner object array.

[Array AddObject];

The destruction of the automatic release pool is the Forin loop to find the OBJC of each array and let it call the release method.

2016-2-Arc Knowledge Summary (two autorelease concepts and implementation)

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.