Generally, when developing a program, we only need alloc and do not need to manage release, because there is arc to help us manage it. However, you still need to know when learning: the memory is limited. If you do not need the memory allocated in the heap area, you need to recycle it. Otherwise, the memory will crash if it is not enough.
So the principle is: if there is allocation, there will be recycling. However, this allocation may be allocated several times. How can this problem be solved? This isReference count. When creating an object, it comes with this reference count.
(1) When alloc, new, copy, mutablecopy, and retain are used, the reference count is + 1, that is, retaincount + 1;
(2) When release is used, the reference count retaincount is reduced by 1.
(3) The missing assign will not add a reference count + 1, because assign is equivalent to an alias for the original object pointer, but the pointer address and the content pointed to by the pointer remain unchanged.
Specific respectively, You can see xiaoxuan%315 before an article: http://blog.csdn.net/xiaoxuan415315/article/details/8061084
We also know that:
// The following statement has the same effect as asstudent * Zhang = [[asstudent alloc] init]; asstudent * Zhang = [asstudent new];
[OC learning-11] alloc, assign, new, retain, copy, mutablecopy, and release in arc and Memory Management