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)