OBJECTIVE-C Memory Management Principles

Source: Internet
Author: User

Memory Management policy
The basic model for memory management is defined in the NSObject protocol and standard method naming conventions in the combination method provided in the reference counting environment. The NSObject class also defines a method: Dealloc, which is automatically recycled when an object is called, this article describes the basic rules you need to know in the Cococa program, and provides many of the correct usage examples Basic Memory management rules policy
the memory management model is object-based ownership. Any object may have one or more owners, as long as an object has at least one owner, let him continue to exist, if an object does not have an owner, the running system will automatically destroy it. To make it clear that you have an object, cocoa has the following policies in place: you have all the objects you createYou can create an object by means of "alloc", "new", "Copy" or "Mutablecopy" (such as Alloc, NewObject, or mutablecopy). you can get ownership of an object by "retain"a received object is usually guaranteed to remain valid. This method can also safely return the calling program object when he is received within this method. You can use "retain" in two ways: (1), in the implementation of an access method or the "Init" method, in order to get the ownership of an object that you want to store as a property value. (2), in order to prevent an object because of some other operational consequences of this is invalidated (such as to explain to avoid the object you are using reallocation Unit) when you no longer need him, you have to give up ownership of the objects you own .you discard ownership of an object by sending it a release message or a autorelease message. In Cococa terminology, discarding the ownership of an object is often referred to as the "release" Objectyou can't release ownership of an object that you don't own.This is only an inevitable result of the above-mentioned policy rules, with clear provisionsThe above is purely their own translation, the level of limited, the great God if there are good resources to share 

OBJECTIVE-C Memory Management Principles

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.