Memory Management in oC

Source: Internet
Author: User
• Memory management refers to memory management. operations involved include allocating memory. For example, creating an object increases memory usage and clearing memory. For example, destroying an object, can reduce memory usage • management scope of memory management any object that inherits nsobject is invalid for other non-object types (INT, Char, float, double, struct, Enum, etc) • the essential reason for memory management is only required for OC objects. OC objects are stored in the heap and non-OC objects are generally stored in the stack (the stack memory will be automatically recycled by the system) • How does the system determine when to recycle the memory occupied by an object? According to the Reference Counter of the object • What is the reference counter each OC object has its own reference counter it is an integer literally, it can be understood as "the number of times an object is referenced" or as follows: It indicates how many people are using this object • to manage the memory occupied by the object, you must learn to operate on the reference counter of an object • Common Operations of the reference counter send a retain message to the object, so that the reference counter value + 1 (the retain method returns the object itself) send a release message to the object. The reference counter value-1 can be used to send a retaincount message to the object to obtain the current reference counter value. • The memory management principle officially stipulated by Apple who creates the release: if you create an object through alloc, new, or [mutable] copy, you must call release or autorelease who retain who release: as long as you call retain, you must call release once. In summary, there is a reduction in the counter + 1 of the object, the basic function of the object counter-1 • autorelease method must be used to send an autorelease message to the object. The object will be placed in an automatic release pool. When the automatic release pool is destroyed, A release operation will be performed on all objects in the pool. After the autorelease method is called by the object itself, the counter of the object remains unchanged.

Memory Management in oC

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.