Memory Management Principles for iOS development

Source: Internet
Author: User
  • When you create an object using the new alloc COPY method, the reference count of this object is 1. When you are not using this object, you are responsible for sending a release (or autorelease) message to this object.
  • When you obtain an object through any other method, we (the caller of the method and the implementer of the method) assume that the reference count of this object is 1 and has been set to automatically released. If you use it as a temporary object, you do not need to perform any release (release or autorelease) operations. But if you want to own it, or you want to save it as a member variable,Then you need to add the reference count to 1 when saving the object (generally in the setxxx method), After the operation is completed (usually in dealloc), release the object (reference count minus 1)

Generally, setxxx is implemented as follows:

-(Void) setxxx: (nsobject) OBJ {

[OBJ retain];

[M_var release]; // m_var is a member variable.

M_var = OBJ;

}

Do not use memory pools or garbage collection on the iPhone!

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.