Memory Management policy
The basic model for memory management is defined in the NSObject protocol and standard method naming conventions in the combination method provided in the reference counting environment. The NSObject class also defines a method: Dealloc, which is automatically recycled when an object is called, this article describes the basic rules you need to know in the Cococa program, and provides many of the correct usage examples
Basic Memory management rules policy
the memory management model is object-based ownership. Any object may have one or more owners, as long as an object has at least one owner, let him continue to exist, if an object does not have an owner, the running system will automatically destroy it. To make it clear that you have an object, cocoa has the following policies in place:
you have all the objects you createYou can create an object by means of "alloc", "new", "Copy" or "Mutablecopy" (such as Alloc, NewObject, or mutablecopy).
you can get ownership of an object by "retain"a received object is usually guaranteed to remain valid. This method can also safely return the calling program object when he is received within this method. You can use "retain" in two ways: (1), in the implementation of an access method or the "Init" method, in order to get the ownership of an object that you want to store as a property value. (2), in order to prevent an object because of some other operational consequences of this is invalidated (such as to explain to avoid the object you are using reallocation Unit)
when you no longer need him, you have to give up ownership of the objects you own .you discard ownership of an object by sending it a release message or a autorelease message. In Cococa terminology, discarding the ownership of an object is often referred to as the "release" Objectyou can't release ownership of an object that you don't own.This is only an inevitable result of the above-mentioned policy rules, with clear provisionsThe above is purely their own translation, the level of limited, the great God if there are good resources to share
OBJECTIVE-C Memory Management Principles