Nineth. Memory management is primary. (Memory management mode, reference counting mechanism and various methods of impact count, Dealloc method, Basic principles of memory management, mastering copy implementation)

Source: Internet
Author: User

I. How memory is managed.
1. Reasons for memory management: 1>.because the memory of the mobile device is extremely limited, so the memory of each app is also limited, when the app consumes more memory, the system will issue a memory warning, you need to reclaim some no longer need to continue to use the memory space, such as recycling some of the unused objects and variables. Managed Scope: Any object that inherits NSObject and is not valid for other basic data types. 2> The intrinsic reason is that because the object and other data types are not stored in the system, the other local variables are stored in the stack, and the objects are in the heap, and when the block ends, all the local variables involved in the block are recycled, and the pointer to the object is recycled. At this point, the object has no pointer pointing, but it still exists in memory, causing a memory leak. 2. Memory FAQ in two aspects: memory overflow, wild pointer exception.Memory Overflow:iOS gives each application a certain amount of memory for the program to run. Once the memory limit is exceeded, the program is crash. (IPHONE3GS memory 30M or so, iphone 5S memory 80M or so.) The largest memory in the program is the picture and audio resource files.Wild pointer problem: The object memory space has been reclaimed by the system and still uses pointers to manipulate the memory. Wild pointer anomaly is the main reason of program crash . The larger the code size of the program, the less easy it is to find the location of the wild pointer.3. How memory is managed garbage collection (garbage collector garbage collector referred to as GC): Programmers just need to open up memory space, do not need to use code to display the release, the system to determine which space is no longer used, and reclaim these memory space, For redistribution. The entire process does not require code, and the system is automatically recycled.the garbage collection technology is always used in the development of J Ava. MRC (Manual reference count Manual Reference count): The opening and releasing of memory is controlled by the program code. Compared to garbage collection, memory control is more flexible, It is possible to release the programmer at a time when it needs to be released, and programmers should be familiar with the mechanism of memory management. ARC (Auto reference count Auto Reference count): ios5.0 compiler feature that allows users to open up space without releasing space. It's not garbage collection! It is still the MRC, but the compiler helps the programmer to add the freed code by default. two. The reference counting mechanism, which affects the various methods of counting.three. Dealloc MethodFour. Principles of memory management.Five. Mastering the implementation of copy

Nineth. Memory management is primary. (Memory management mode, reference counting mechanism and various methods of impact count, Dealloc method, Basic principles of memory management, mastering copy implementation)

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.