Shallow copy: Copies only pointers to objects, not the reference object itself. Counter +1, like retain, for example.
Deep copy: Copies the reference object itself. The counter does not change, resulting in a new object
Retain: Always shallow copy. The reference count is added one at a time. Returns whether the object is mutable and consistent with the object being copied.
Copy: The reference count does not change for a deep copy of a mutable object, and for an immutable object is a shallow copy, the reference count is added one at a time. Always returns an immutable object.
Mutablecopy: Always deep copy, reference count does not change. Always returns a Mutable object.
Application: Array type conversion:
1. Immutable objects → conversion of mutable objects [XXX mutablecopy]
2. Variable objects → conversion of immutable objects [XXX copy]
3. Variable object → variable object conversion (different pointer variable pointing to different memory address) [XXX mutablecopy]
4. Pointer duplication between objects of the same type (different pointer variables point to the same memory address) [XXX copy]
When multiple pointers point to the same area of memory, these pointers also have ownership of the memory area. The process of the partition of ownership, when it is necessary to use a shallow copy.
Shallow copy, deep copy in Objective-c