IOS Foundation Fifth day (0809)

Source: Internet
Author: User

0809-memory management, only valid for OC objects. Alloc, retain, release, Retaincount Local variables are placed inside the stack, OC objects are placed in the heap. The content system inside the stack is automatically recycled, and the contents of the heap are still there, so it is not suitable for arc to manually reclaim the content of these objects.

As shown in the following:

Basic structure of the object
    • Each object has a reference counter, occupies 4 bytes, is an integer, when the value of the reference counter is 0, the object will be destroyed by the system. When an object is just born, the value of this counter is 1 .

As shown in the following:

Role of reference counter

As shown in the following:

Actions that reference counters

As shown in the following:

Destruction of objects

As shown in the following:

Wild Hands
    • Wild pointer: Pointer to the Zombie object (not available memory, this memory has been freed). For example: [P release] performs multiple releases. This may be an error if you open the zombie probe switch under scheme.

Switches such as:

Also the pointer phenomenon is as follows:

Specific error phenomena such as:

To prevent the wild pointer from pointing the pointer to nilp = nil;

A summary of some memory

Such as:

There's alloc, there's a release, there's retain. If you manually implement a method of a member variable, the real name of the member variable is notname out. If you still want to use theName will be written in @interface{} manually _name

As shown in the following:

Or

Auto Release pool Autoreleasepool Auto Release autorelease
    • The release method of releasing the object in the pool is automatically called once the method in the auto-release pool is executed
    • Auto-free pool can nest auto-free pool
    • The auto-release pool is placed in the stack
    • Automatic release of objects in the pool cannot be controlled precisely. Only the release method of all objects is called when the auto-free pool method executes, and the object's reference counter-1, in time-1, is not necessarily free, and it needs to look at its own memory control.

Automatic release of the pool stack structure:

To automatically release the pool code structure:

IOS Foundation Fifth day (0809)

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.