Oc2_ reference count

Source: Internet
Author: User

////Dog.h//oc2_ Reference Count////Created by zhangxueming on 15/6/18.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>@interfacedog:nsobject{NSString*_name; Nsinteger _age;} @property (copy, nonatomic) NSString*Name: @property (nonatomic) Nsinteger age;@end////DOG.M//oc2_ Reference Count////Created by zhangxueming on 15/6/18.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "Dog.h"@implementationDog@end
////main.m//oc2_ Reference Count////Created by zhangxueming on 15/6/18.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>#import "Dog.h"//Manage Memory methods://Auto Reference count automic refence counting//Manual reference count manual refence counting//gar--automic refence Counting Yes --NointMainintargcConst Char*argv[]) {@autoreleasepool {Dog*xiaobai =[[Dog alloc] init]; NSLog (@"Retaincount =%li", Xiaobai.retaincount); //keep the object input, increase the ownership of the object, and add 1 to the reference count; //The premise of retain is that the object existsDog*xiaohei =[Xiaobai retain]; //Dog *xiaohei = Xiaobai; Just Xiaohei's pointer is pointing to Xiaobai, and there is no Retaincount plus 1.NSLog (@"Retaincount =%li", Xiaohei.retaincount); Dog*xiaofei =[Xiaohei retain]; NSLog (@"Retaincount =%li", Xiaofei.retaincount); //release releases object ownership, referencing the value of counter -1;[Xiaobai release]; Xiaobai=Nil; NSLog (@"Retaincount =%li", Xiaofei.retaincount);        [Xiaohei release]; Xiaohei=Nil; NSLog (@"Retaincount =%li", Xiaofei.retaincount); [Xiaofei release];//retaincount = 0 DeallocXiaofei =Nil;//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining");//NSLog (@ "The weather is fine today, it's Raining"); //after the object is freed, no more messages can be sent to the object//NSLog (@ "Retaincount =%li", xiaofei.retaincount);    }    return 0;}

Oc2_ reference count

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.