The difference between the iOS memory nil and release

Source: Internet
Author: User

    • The difference between the iOS memory nil and release

Category: iOS memory management

The role of Nil and release:

Nil is to set the pointer of an object to null, just cut off the pointer to the object in memory, and release is the real notification of memory release this object, but in iOS does not immediately release memory, but the memory counter cut off 1, until the counter becomes 0, will release memory So the purpose of release is to free up memory, and Self.object = nil, is to empty the pointer.

So nil does not release memory, only release to really free memory.

The order in which they are used:

If it is nil without release, then it is tantamount to making a memory leak because nil after release has no effect.

Conversely, if the interface object is used only if release is not set self.myoutlet = nil, then the program may not error, but it will be very unstable, not robust, prone to crashes.

Since an interface object has been released after release, the memory allocated to it has been freed, and the program will be crash if the object is re-used after the release.

If you set the pointer to empty after releasing it, it will not crash even if the object is used by the subsequent program.

This article is from the Linux commune website (www.linuxidc.com) Source Link: http://www.linuxidc.com/Linux/2012-06/62035.htm

Strong similar to retain

Weak similar to assign

The difference between the iOS memory nil and release

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.