The MRC and ARC memory management mechanisms of OC Note: Xcode4 did not previously have arc.

Source: Internet
Author: User

1 . MRCin objective-c language (mannulreference counting)

   in MRC retain,release and autorelease retain and release nsautoreleasepool object, To join the auto-release pool ( autorelease Called), when drain When the memory is reclaimed.

(1)retain, the function of this method is to attach the ownership of the memory data to another pointer variable, the reference number plus 1, namely retaincount+= 1;

(2)Release, the method is to release the pointer variable to the memory data ownership, the reference number minus 1, that is retaincount-= 1;

(3)autorelease, the method is to put the object memory management into autoreleasepool .

2. ARCinobjective-c language (automaticreference counting )

Memory management-related identifiers in ARC can be divided into variable identifiers and attribute identifiers, __strong for variables , __weak by default , strong and for attribute table have:

@property (nonatomic/atomic,assign/retain/strong/weak/unsafe_unretained/copy,readonly/readwrite) Number* num;// default is unsafe_unretained .

There are also Autoreleasepool.

the ARC management mechanisms that are required for the Core Foundation to be exchanged with objective-cobject are:

(1) (__bridge_transfer<nstype>) op oralternatively cfbridgingrelease (OP) isused to consume a retain-count of a CFTyp Eref whiletransferring it over to ARC. This could also is represented by id someobj = (__bridge <NSType>) op; Cfrelease (OP);

(2) (__bridge_retained<cftype>) op oralternatively cfbridgingretain (OP) isused to hand an nsobject Overto CF-land wh Ile giving it a +1 retain count. You should handle a cftyperefyoucreate this is the same as you would handle a result of cfstringcreatecopy (). This could also is represented by Cfretain ((__bridge cftype) op); Cftyperef sometyperef = (__bridge cftype) op;

(3) __bridge justcasts between Pointer-land and Objective-c Object-land. If you had noinclination to use the conversions above.

The MRC and ARC memory management mechanisms of the

OC Note: Xcode4 did not previously have arc.

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.