How to view reference count changes in the ARC environment?

Source: Internet
Author: User

How to view reference count changes in the ARC environment?

 

1. Create a new project to test the changes in the reference count.

 

 

 

2. Find the following path: Build Phases ----> Compile Sources ----> AppDelegate. m

 

 

 

3. Select the AppDelegate. m file ,.

 

 

 

 

4. Set Compiler Flags of AppDelegate. m to "-fno-objc-arc "..

This is because we need to write our test code in the AppDelegate. m file. By default, the project manages the memory by ARC. Therefore, we use the parameter "-fno-objc-arc" to set it to manual memory management.

 

 

 

5. Enter the following code in AppDelegate. m:

 

 

- (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;}

 

 

6. Start coding. And run. Output result:

 

21:35:46. 252 Demo of reference count change under ARC [2070: 86317] object-12015-07-14 21:35:46. 252 Demo of reference count change under ARC [2070: 86317] object-22015-07-14 21:35:46. 253 Demo of reference count change under ARC [2070: 86317] object-1

 

 

References:

Advanced iOS development-Tang Qiao.

 

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.