Objective-c Memory Management 2 Lan Yi Education

Source: Internet
Author: User

Three methods commonly used in manual memory management (MRC)

Retain: Causes memory Count +1

Release: Causes memory Count -1

Copy: Copies a new object and the data of the previous object may be consistent but not the same object memory count is 1

Autorelease: Automatically released when the variable is automatically released from the pool

Auto-Release Pool There's a lot of invisible in the project.


Attribute Description Keywords:

Retain/strong:

if retain would do two things ,

-(void) Setnames: (Nsmutablearray *) names{

The first thing to release-1 the original

[_names release];

the second thing to pass in the new retain +1

_names = [names retain];

//

//

//}

The attribute life time retain plus 1 executes the Dealloc method when the current object is destroyed release-1


Assign/weak:

If this is the assign or weak set method, only one thing is done.

-(void) Setage: (int) age{

//

_age = age;

//

//}



Copy

If you're doing one thing in the copy set method

-(void) Setnames: (Nsmutablearray *) names{

//

_names = [names Copy];

//}


ReadOnly: If ReadOnly is used, the property will only generate a Get method without a set method


Nonatomic: Non-atomic Operation unsafe efficiency high non-multithreading are used Nonatomic

Atomic: Atomic operation thread security inefficient only when multiple threads access data can you use this keyword


All basic data types are assign or weak but because they are the default, you don't have to write anything.


All object types (except NSString) are used with strong or retain


NSString needs to be modified with copy to avoid a chain reaction that alters a string that causes a series of related strings to change.












This article is from the "Get" blog, so be sure to keep this source http://3517465.blog.51cto.com/3507465/1692010

Objective-c Memory Management 2 Lan Yi Education

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.