How to view the change of reference count in arc-environment

Source: Internet
Author: User

First, create a new project to test the change in reference count.

Second, find the following path build phases---->compile Sources---->APPDELEGATE.M

Three, select the APPDELEGATE.M file.

Four, set APPDELEGATE.M's compiler flags to "-fno-objc-arc".

This is because we are going to write our test code in the APPDELEGATE.M file. The project, by default, is the arc-managed memory. So, we'll use the parameter "-fno-objc-arc" to set it to manually manage memory.

Five, enter the following code in the APPDELEGATE.M:

1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 <span style="font-size: 18px;">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.            NSObject *object=[[NSObject alloc]init];    NSLog(@"object-%ld",[object retainCount]);    NSObject *another=[object retain];    NSLog(@"object-%ld",[object retainCount]);    [another release];    NSLog(@"object-%ld",[object retainCount]);    [object release];      return YES;}</span>

Six, begin to write the code. and run. Output results;

1 2 3 4 <span style="font-size: 18px;">2015-07-14 21:35:46.252 ARC下引用计数的变化Demo[2070:86317] object-12015-07-14 21:35:46.252 ARC下引用计数的变化Demo[2070:86317] object-22015-07-14 21:35:46.253 ARC下引用计数的变化Demo[2070:86317] object-1</span>

Resources:

iOS Development advanced-Tang Qi.

How to view the change of reference count in arc-environment

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.