- When you create an object using the new alloc COPY method, the reference count of this object is 1. When you are not using this object, you are responsible for sending a release (or autorelease) message to this object.
- When you obtain an object through any other method, we (the caller of the method and the implementer of the method) assume that the reference count of this object is 1 and has been set to automatically released. If you use it as a temporary object, you do not need to perform any release (release or autorelease) operations. But if you want to own it, or you want to save it as a member variable,Then you need to add the reference count to 1 when saving the object (generally in the setxxx method), After the operation is completed (usually in dealloc), release the object (reference count minus 1)
Generally, setxxx is implemented as follows:
-(Void) setxxx: (nsobject) OBJ {
[OBJ retain];
[M_var release]; // m_var is a member variable.
M_var = OBJ;
}
Do not use memory pools or garbage collection on the iPhone!