Http://blog.csdn.net/lifengzhong/article/details/7739496
The basic data type is value type, which is stored on the stack and allocated and recycled by the compiler. The programmer can use it immediately after it is declared. NSObject objects and their subclasses are of reference type and stored on the stack. The programmer is responsible for allocation and collection. Objects should be released immediately after they are used up. In some cases, objects are assigned and initialized and passed to another method. In this case, the programmer no longer has control over the object, you can call the autorelease method of an object to throw the object to the automatic recycle pool, which is less efficient. If you have ownership of an object, you need to take charge of its recycling work. Otherwise, you do not need it or retrieve the objects you do not own.
1: All objects returned by functions starting with alloc, new, copy, or mutabelCopy and these keywords are owned by you, that is, the memory Recycle of these objects. This is a convention in iOS development. Therefore, when writing your own alloc, new, or copy functions, follow this naming convention.
2: The object returned by retain has ownership. For example, display the result returned by calling the retain function or a member variable of the retain type of synthesize. 3: no ownership of all objects returned using other functions.
4: the reference of the returned object, with no ownership.
5: The object returned by autorelease has no ownership.
After the methods are used to declare and assign objects, the programmer does not need to do anything to release the objects. After the CPU command leaves the method, the allocated objects defined in the method are automatically released. Instance variables/attributes are different. In a method, if we are sure that we no longer need an instance variable/attribute, we can set the nil value for the object, to ensure that the resources occupied by class instance variables/attributes are correctly released after the CPU command leaves this type of instance. Generally, the instance variable/attribute is set to nil in the viewDidUnload function.