iOS memory management Little Talk

Source: Internet
Author: User

What memory management is memory managed by? What we want to manage is the memory space of the heap area and any object that inherits NSObject  1. The first thing to be clear is that the memory is divided into five areas, namely, the stack area, the heap area, the BSS section, the data area and the code area, the  2.BSS segment, Data area and code area these three areas are loaded into memory space as the program starts, and the global variables we know are stored here, but in two cases: if it's an uninitialized global variable, it's stored in the BSS segment, and if it's an initialized global variable, it's stored in the data area. Many times we don't recommend that you create global variables because if a program starts, the global variables stored here will load as the program starts, allocating memory space, which can cause the program to load very slowly. But one thing to be clear is that the three areas are automatically managed by the system, so our memory management is not the management of these three areas  3. Then there is the stack area and the heap area, the first thing we need to know is that in memory allocation the address of the stack is from high to low allocation, the address of the heap area is from low to high allocation , and the basic data type we know is stored in the stack, and it occupies a certain amount of  4. Second, there are local variables stored in the stack, and the space of the local variable does not need to be recycled, but the code block or function that it resides in is automatically recycled at the end. Therefore, the memory space of the stack area does not require the programmer to manage the  5. Finally only the heap area is left, so we can basically determine that the memory management we want to learn is the management of the heap area memory space, but we have to analyze the heap area and then make the decision  6. The statement we used to create the object in OC is new, The three steps of new are: 1. Allocate a chunk of memory space in the heap area 2. Initialize the Created Object 3. return address; We saw it was allocated in the heap area! So all we have to do is manage the space in the heap, consider when the heap is going to be applied, when to recycle it, and because of the reason we created the object, memory management actually manages any object that inherits from NSObject, but not the other base data types. So here we should know that the memory management we are talking about in OC is actually the memory space of the research heap and any object that inherits NSObject!  7. When we analyze this, we must realize that we understand the knowledge of each of the small passages above, but we have never logically connected them together; we're talking about the nature of memory leaks after we know exactly what memory management is going to manage.   8. The intrinsic reason for memory leaks is that objects are stored in the heap area, local variables and pointers are stored in the stack area, and when a program is executed, all local variables involved in the code block are reclaimed by the system, andPointers to objects are also reclaimed by the system, and at this point the objects that exist in the heap do not have pointers pointing but still exist in memory, causing memory leaks

iOS memory management Small Talk

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.