Retention of objects and release of ownership:
int main (int agrs,char *argv[]) {@autoreleasepool {Person *person = [[Person alloc]initwithname:@ ' Tom ']; Retaincount=1[Person Setname:name]; Retaincount = 2;[person release];}} @interface Person@property (Nonatomic,retain) (nsstring*) name; @endin detail: A Perosn object is created in main function main, at which point the main function has ownership of the object person, retains the counter retaincount=1, and immediately thereafter, because the instance variable of class person name type retain is a strong reference, , when the person object in the main function calls the SetName method, the class person also has ownership of the person object,Therefore, the person class will keep the counter plus 1 to hold the person object, at this time of the retaincount=2; According to the principle that the object who created, who released, the main function in the main function of the Perosn object is used by the main function to release its ownership, The main function is immediately removed. At this point, keep the counter retaincount=1, at which time the system does not call the Dealloc method to destroy the object, and the object is reserved to the class person. By the end, after the class person has run out of object person, the class person should also release ownership of the person object, so call the overridden Dealloc method to release the person ownership in this method, retaincount= 0, after completing the "Super Dealloc" of the parent class, the Perosn object is completely destroyed. In short two words: (1) Who calls this object, it must obtain its ownership, the object is retained, to prevent direct destruction;(2) who created the object, who was responsible for releasing it; who called the object, who was responsible for releasing it.
Objective-c: A detailed explanation of the idea of preserving the counter (retention of objects and release of ownership)