1, What is a reference count
All OC objects have a counter called a reference count, which is a reference count that currently has several objects in use (a reference to hold the object);
2, What is Object ownership
A object has a reference to a B object, anda object has ownership of the B object;
3, Under what circumstances need retain
The owner of a object adds another, so the a object has a count plus 1, and you need to use retain (that is,when other objects need the object, that is, the other pointer points to the object, the reference count of the object is added 1 You need to send a retain message to the object at this point)
4, What circumstances need release
The owner of the a object is reduced by another, then the owning count of a object is reduced by 1, and releaseis required (that is, when the object's owner no longer needs it, it can be sent to the object Release message to reduce the reference count of the object by 1)
5, What's wrong with wild pointers , How to avoid wild pointers and zombie objects
A wild pointer is a pointer to an object that occupies a memory that has been destroyed, and the wild pointer causes the program to crash and is not easy to detect;
A Zombie object is an object occupied by memory that has been destroyed -- after releasing a memory, if the pointer needs to either assign a new value or give nil;
6, What is the auto-release pool?
Auto-free pool is an automatic memory management mechanism of OC, and when the automatic free pool is destroyed , the objects in the pool are called to the release method;
Use the autorelease method to put an object into an auto-release pool containing it; the auto-free pool is essentially the release method of calling an object when the pool is destroyed automatically , not necessarily destroying the object ( For example, if the reference counter of an object is >1 then it cannot be destroyed at this point, just make the object's reference count-1)
7, What is a strong pointer , What is a weak pointer
Strong pointers , owning object ownership, reference count +1
Weak pointers, which can reference objects, do not have ownership of objects, and reference counts do not change
What's the difference between 8,assign,strong,weak?
Strong : ( Default value for object properties under ARC environment) strong pointer , ownership of Object , equivalent to retain, reference count +1. As long as the ARC mechanism is used , the OC object type is recommended for use with strong, not using retain
Weak: (ARC) weak pointer , can reference object , equivalent to assign assignment , does not own object ownership , the reference count does not change. Weak applies to OC objects ① weak pointers are released after the instance object to which they point ? Automatically becomes nil ② that is, when an instance object pointed to by the weak pointer is freed , the weak pointer does not become a wild pointer
Assign : For non-pointer types (for basic data types)
9, How to resolve a circular reference between two objects
Use weak references; set one of two objects as a weak reference
IOS Memory Management (i) Basic knowledge introduction