iOS Learning Summary (ii)

Source: Internet
Author: User

Fourth Chapter memory Management

NSAutoreleasePool * Pool = [[NSAutoreleasePool alloc] init]; [Pool drain];

In fact, there can be multiple auto-release pools in the program. The auto-free pool does not actually contain the actual object itself, just a reference to the disposed object. You can add an object to an autorelease message by sending it to the current auto-release pool.

Reference count:

Concept: When you create an object, you set its number of references to 1, and each time you must persist the object, you send a retain message, which adds 1 to its reference count.

[Myfraction retain];

When an object is no longer needed, you can reduce the number of references to the object by 1 by sending the release message. [Myfraction release];

When the reference count is 0, the system frees its memory by sending an DEALLOC message to the object. The reference count of this object can be obtained by sending an Retaincount message to the object, and the Nsuinteger integer is returned. The system does not release the memory used by the object as long as the object's reference count is not 0.

Adding an object to any type of collection will increase the reference count for that object. Removing an object from any collection can reduce its reference count.

In-memory constant strings do not have a reference counting mechanism, because these objects can never be freed. This is also true for immutable string objects initialized with constant strings.

When a piece of code needs to access an object, the object's reference counter is incremented by 1, and when it is 0 indicates that no longer has code to access the object, the object is destroyed (by calling the Dealloc method).

iOS Learning Summary (ii)

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.