Memory Management and Memory Management Software

Source: Internet
Author: User

Memory Management and Memory Management Software

======================================

Memory Management

======================================

 

[Q] What did memory management do?

How to create and release memory in oc.

 

Oc Memory Management

Manual memory management MRC]

Previously, Xcode5 was used for manual memory management.

[Q] Why do I need to learn how to manage the memory manually?

[Answer] At present, projects with manual memory management still exist.

 

Arc to mrc: Project-> targets-> build Settings-> Search: gar; Set yes-> no

 

[Memory Management in C Language]

1. The created memory is not released after it is called [Memory leakage]

2. Release the same memory multiple times, which is called "repeated release]

3. Memory Management is very inconvenient in the thread, and the program crashes due to the release of multiple references.

4. Modular programming in C language, with a wild pointer.

 

[Memory Management in oc] Reference Counter

1. the reference counter can be understood as a pointer counter. It references an object once, the heap space counter is + 1, and the reference counter is released once. The counter is-1. When the counter is 0, object Memory release;

 

[Memory Management in oc]

1. Strictly release a heap space multiple times (release ). [Repeated release]-[Crash]

2. Strictly Create memory for a heap space without releasing it. [Memory leakage]-[memory only increases and does not decrease]

 

[Total] memory management in oc, who creates, who releases, which class creates, which class is responsible for release, which class is alloc, and which class is release;

 

[Total] [mrc] In oc, such as alloc, retain, copy, mutablecopy (or the system method starting with mutablecopy and copy) and new, all of which require release/autorelase;

 

Retain references counter + 1, or the current memory object;

Copy Copies a new memory space (mutablestring), which cannot be modified.

Mutablecopy copies a new memory space (mutablestring), which can be modified.

 

[Note]

STACK: for the operating system, the local variables in function parameters or methods are in the stack space.

Heap: for the operating system, the programmer is responsible for allocating and creating or releasing the memory, all of which are in the heap space.

 

[Related methods]

1. If alloc memory is in the constructor, the memory needs to be released in the Destructor (delloc) function.

2. If a member variable pointer is transferred, retain is required first;

3. Select a value from the data structure. If you want to retain the value for a long time, you need to retain it;

 

[Automatic Memory Management in MRC]

1. The automatic release pool can be understood as delayed release (automatic release );

2. The autorelease method can be used to automatically release the pool. The autorelease method does not work if the pool is released automatically;

 

[Automatic release usage]

1. It is generally used in local methods;

2. used in non-usable situations;

3. In mrc, The alloc object to be returned can be handed over to the system for automatic memory release by adding the autorelease method.

 

[Attribute variable modifier]

1. copy

2. retain

 

[Supplement]

1. Generally, when the heap space in the method is released, try to write release at the bottom of the method to avoid the issue of releasing in advance.

2. in a strict sense, the mrc project outperforms the arc project in terms of performance, but in terms of use, the arc performance is superior to the mrc; in terms of coding, the arc is less workload than the mrc; from a security perspective, arc is superior to mrc. [cell phone performance surplus]

[How to detect memory leakage] product-> Analyze; this will Analyze the problematic code in the process

 

[Automatic Memory Management ARC]

Memory is automatically managed after Xcode5

[Mrc To arc] Edit-> convert-> To Object-c arc...

[Note] This operation is irreversible.

 

[Use Mrc in the arc project] project-> Targets-> Build Phases, select the first class to close. m file, double-click the Input-fno-objc-arc; in this way, the related. m files are set to files managed by mrc

 

[Disadvantages of Automatic Memory Management]

1. automatic Memory Management some code still needs manual management, not to say that manual release is required. attribute variables in arc do not have strict requirements for using retain, strong, and weak; however, there are requirements for mixed arc and non-arc editing.

 

Related Article

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.