Objective-C memory managementTwo
Three methods commonly used in manual memory management (MRC)
retain: causes the memory count to be +1
release: causes memory count -1
copy: Copy a new object and the data of the previous object may be the same, but not the same object The memory count of this object is 1
autorelease: Automatic release automatically releases the variable when it comes out of the autorelease pool. There are many invisible property description keywords in the project: retain / strong: // If it is retain, it will do two things //-(void ) setNames: (NSMutableArray *) names {// // The first thing is the original release -1 // [_names release]; //// The second thing is the newly passed retain +1 // _names = [names retain]; // // //} The 1 added to retain during the lifetime of the property will be released -1 when the dealloc method is executed when the current object is destroyed. One thing //-(void) setAge: (int) age {// // _age = age; // //} copy: // do one thing in the copy set method //-(void) setNames: (NSMutableArray *) names {// // _names = [names copy]; //}
readonly: if modified with readonly, the property will only generate the get method and no set method
nonatomic: Non-atomic operations are not safe and efficient. Nonatomic atomic is used. Nonatomic atomic: Low thread safety and efficiency of atomic operations. Only when multiple threads access data, it is possible to use this keyword. All basic data types use assign or weak. But Because it is the default, you do not need to write anything. All object types (except NSString) use strong or retain. NSString needs to be modified with copy. In order to avoid a chain reaction, changing a certain string causes a series of related strings to change.
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.