<span id="Label3"></p><p><p>Knowledge points<br>1. Memory management function<br>2. Principles of memory management<br>3. Golden Rule<br>4.setter/getter<br>5. Properties</p></p><p><p>======================================<br>Memory management<br>1. Memories: memory management through those functions in C language<br>c malloc FREE NULL pointer<br>If (xxx! = Null) {free;}</p></p><p><p>1) What is the trouble with heap space release?<br>2) How to prevent multiple releases<br>3) how to prevent memory leaks<br><br>2.oc Memory Management Method (reference count reference Counting)<br>1) Manual Management (MRC)<br>2) Automatic garbage collection (not available for ios, only for Mac systems after 10.5)<br>3) ARC (Automatic Reference counting, similar to smart pointers in C + +)</p></p><p><p><br>3.http://developer.apple.com</p></p><p><p>The basic rule to Apple is everything the increasesthe reference counter<br>With alloc, [mutable]copy[withzone:] or retain are in charge of the corresponding<br>[auto]release</p></p><p><p><br>1) If you use Alloc for an object, [mutable]copy[withzone:],retain] you must use the appropriate release or Autorelease.</p></p><p><p>2) retain Effect: Preserve object, make object counter +1<br>Alloc action: creates an object and initializes the counter of that object to 1<br>Copy function: copies the object and sets the counter of the new object to 1<br><br>3) Release Function: Object counter-1</p></p><p><p>4. Memory Management class definition<br>1) Basic type: all C types<br>Such as: char, short, int, long, struct, union, enum<br>OC memory Management is not valid for C language base type<br>2) OC Type (non-basic Type)<br>Any object that inherits from the NSObject class belongs to the OC type<br>nsstring, Nsinteger</p></p><p><p><br>Resolving memory problems in OC<br>Introduction of Memory Count Retaincount<br>Each object has a count of attributes Retaincount<br><br>1. As long as the object new,alloc,copy,mutablecopy,retain, it will result in retaincount of the object plus 1<br>2. Calling the Object's method Release,autorelease will reduce the reference count of the object by 1<br>3. When the Object's reference count is 0 o'clock the system automatically calls the Object's destructor dealloc, and this method cannot be called manually<br>4. The C language type in OC does not introduce memory count and does not require memory management (char int float bool Long ... )<br>5. Release the null pointer is legal and will not crash<br>In order to maintain the reference count balance of the object: who causes retaincount increase should be responsible for retaincount reduction</p></p><p><p><br>========================================<br>Setter and Getter functions<br>1. Recall: If you access a member variable in an object<br>The role of 2.setter and getter functions<br>How 3.setter and Getter are named<br>Memory management in 4.setter and getter<br>=======================================<br>Dot syntax<br>1. Recall: If a member variable in an object can be like a struct in C and a class in C + +, access internal variables through the dot operator<br>2. The role of Dot grammar<br>3. The relationship between point syntax and Setter/getter function<br>============================== m =========<br>Property and Composition (synthesize)<br>1. Think: When there are very many member variables in a class, will the setter and getter appear bloated<br>How to make the code more concise<br>2.property use<br>1) Let the compiler automate the production of function declarations<br>3.property use<br>1) @property (attribute) Variable type variable name<br>2) property does not expand on attribute name and member name<br>4.synthesize use<br>1) let the compiler automatically implement setter and getter functions<br>======================================<br>Property Properties<br>1. Atomic operation<br>Atomic/nonatomic<br>2. Read and write operations<br>Readonly/readwrite<br>3. Assignment operation<br>Retain/assin/copy<br>4.arc operation<br>Weak/strong<br>As long as an object is pointed to by any of the strong pointers, it will not be destroyed.<br>If the object is not pointed to by any strong pointer, it will be destroyed</p></p><p><p>5.ios-memory Management</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service