Fourth Chapter memory Management
NSAutoreleasePool * Pool = [[NSAutoreleasePool alloc] init]; [Pool drain];
In fact, there can be multiple auto-release pools in the program. The auto-free pool does not actually contain the actual object itself, just a reference to the disposed object. You can add an object to an autorelease message by sending it to the current auto-release pool.
Reference count:
Concept: When you create an object, you set its number of references to 1, and each time you must persist the object, you send a retain message, which adds 1 to its reference count.
[Myfraction retain];
When an object is no longer needed, you can reduce the number of references to the object by 1 by sending the release message. [Myfraction release];
When the reference count is 0, the system frees its memory by sending an DEALLOC message to the object. The reference count of this object can be obtained by sending an Retaincount message to the object, and the Nsuinteger integer is returned. The system does not release the memory used by the object as long as the object's reference count is not 0.
Adding an object to any type of collection will increase the reference count for that object. Removing an object from any collection can reduce its reference count.
In-memory constant strings do not have a reference counting mechanism, because these objects can never be freed. This is also true for immutable string objects initialized with constant strings.
When a piece of code needs to access an object, the object's reference counter is incremented by 1, and when it is 0 indicates that no longer has code to access the object, the object is destroyed (by calling the Dealloc method).
iOS Learning Summary (ii)