oc-Memory management mechanism

Source: Internet
Author: User

1. Memory management mechanism

    • Referred to as "reference count" (retain counting)
    • Each object has a reference count (retain count)

2. Why to manage memory

In our iOS development process, the program memory more than 20M will receive a memory warning, to 30M when the program will be a flash, this may be a lot of developers crash place.

The 3.iOS memory mechanism is mainly divided into ARC and MRC

    • ARC automatically manages memory
    • MRC Manual Memory Management

4. Principles of Memory management

    • The essence of memory management is the management of memory reference count
    • There are +1 must have corresponding-1
    • Only when you see alloc,retain,copy, you need to releas in the current method or in the interior;
    • When a pointer is retain,alloc,copy, it needs to be release within the current method or class.
    • An object created by the convenience constructor, which has been identified within the method once Autorelease
    • Container memory Management: An object is placed in the container, the reference count of this object +1, when the object is removed from the container, the object reference count will be-1.

5. How the system reclaims memory Dealloc

Never call this method

In the MRC, when you rewrite this method, you need to write a [super Dealloc] in the last line;

oc-Memory management mechanism

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.