Summarize IOS 7 Memory management

Source: Internet
Author: User

[Some summary of iOS7]5, memory Management in iOS we know that in order to handle memory management issues more easily, freeing developers from the tedious allocation and release of memory and focusing on products and logic, iOS provides an efficient way to automatically reference count arcs. With Arc, the vast majority of memory management problems do not require us to continue to worry about. But on the other hand, this handy tool also feeds the programmer's lazy mood, and many novices and students don't even know the meaning of reference counting. It is true that this part of the content is relatively difficult to understand, but if it can be deeply understood will be the future of learning and development of the powerful booster. 1, about the concept of object ownership: When an owner (can be an arbitrary objective-C object, it takes ownership of an object by creating or copying an object, and preserving the object in use. The functions that may be involved are:1alloc, Allocwithzone, copy, Copywithzone, Mutablecopy, mutablecopywithzone; retain ;If an owner owns ownership of an object, the owner is obliged to dispose of the object at the appropriate time:release; autorelease; when do you need to focus on object ownership? For example, an object (object A) is a member of another object (object B), and the child object (a) is related to an external object (such as a child object set through an external object). You need to focus on the logic of child object creation and release to prevent issues such as early release, false release, and no release. 2, the Dealloc method acts: It is automatically called by the system when the reference count is 0, frees the current object and reclaims the memory. This function is typically overridden to implement manually cast members that are manually assigned in the object. It is important to note that because some instances of subclasses inherit from the parent class, the Dealloc method of the parent class must be called at the end. 3, point syntax memory management typically specifies a type when defining property properties, such as retain, assign, and so on. The main considerations are three parts: (1) Assignment attribute: assign--Direct Assignment (default); retain--reserved objects, which point to the same instance, reference count +1copy--Copy object, reference count is constant (in rare cases equivalent to retain);2) Read-write: readwrite--Readable and writable (default) to generate setter and getter methods;ReadOnly--Only the Getter method is generated;3) Atomicity: atomic--Atomic Class (default), turn on multi-threaded protection, nonatomic--non-atomic class, there is no thread protection. Once the property is defined, the corresponding memory operation is automatically based on the defined type when setting and reading the member variable using point syntax. 4, auto-free pool autorelease The object created in an auto-free pool can be automatically freed. The NSObject class provides a autorelease message that sends an autorelease to an object to join the auto-free pool. When the auto-free pool is destroyed, a release message is automatically sent to each object in the pool. It is important to note that the auto-release pool does not guarantee that objects in each pool will be successfully cast. Because if the object reference count in the pool is greater than 1, the object will still exist because the auto-free pool sends only one release message. 

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.