Retain count of memory management

Source: Internet
Author: User

If you create an object using Alloc, new, or a method that contains a copy function, you have ownership of the object. (if the retain count of the new object is 1 and is not in the auto-free pool, then you are obliged to release it when you are not using the object). Passing object ownership Some common methods are alloc (and often follow the Init method), copy and Mutablecopy.

Objects created by other means do not necessarily have ownership of the object. (The retain count for the new object is 1, which is placed in the auto-release pool, and if the object is retain before the auto-free pool is emptied, it will not be released, otherwise the object will be released).

Join does not own the ownership of an object, but want it to exist, can occur retain message to take ownership (this step increased the retain count)

Release and autorelease messages can occur when there is ownership of an object, but it is no longer needed. (the release message immediately reduces the retain count; the autorelease message only causes the release message to occur when the auto-free pool is emptied.) )

Only the object has an owner, and the object is not freed. (The DEALLOC message is sent when the retain count becomes 0 o'clock)

Retain count of memory management

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.