Memory Management Principles

Source: Internet
Author: User

1. Release the objects created by the alloc method, the objects copied by the copy and mutablecopy methods, and the objects that manually call retain. The alloc method creates a new object and sets the object retention count to 1. The copy and mutablecopy Methods create a copy of the object and set its retention count to 1. Manually calling retain will increase the retention count of the object by 1 to ensure that the object will not be recycled during use. All three methods require us to manually call release for release.

2. The automatically released object does not need to call release, because the released responsibility has been transferred to the automatically released pool.

3. Just do it yourself. If you obtain an object provided by other methods, you do not need to consider the memory management of the object. However, if you want to use the object for a period of time, you need to keep the object and release it after use (to prevent the object from being released during use ).

4. Keep in mind the above three memory management principles without relying on the retaincount method returned by the reserved Count value (http://yeeyaa.me/articles/2011/04/avoid-getting-object-reference-count-using-retaincount/
).

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.