OC17 memory management and automatic reference counting

Source: Internet
Author: User

  VIEWCONTROLLER.M//  OC17 memory management and automatic reference counting////  created by zoujie  ON 15/10/25.//  COPYRIGHT ? 2015 year  zoujie. all rights reserved.//# import  "ViewController.h" #import   "Fraction.h" @interface  ViewController  () @ end@implementation viewcontroller-  (void) viewdidload {    [super  Viewdidload]; #pragma  mark  basic knowledge of memory management/application not enough memory to sit more things, there is a possibility of collapse. Memory management is concerned with cleaning up (recycling) unused memory so that memory can be reused.     1. Frees memory//    2 that are not used by objects. Determines that the object does not need to use//    3. Reference count (manual, used to support legacy non-ARC engineering)     [self managermemorybymyself];//    4. Xcode4.2 after   ARC  Auto reference count     [self autoARC];         }-(void) managermemorybymyself{//     when an object is created, the initial reference count is 1//      whenever creating a reference to an object needs to be a reference object +1  , send RetaiN Message     id obj,obj1;//    [obj retain];//      &NBSP by sending the release message to an object when the object is not needed; 1//    [obj release];    for reference counting  //     when the reference count is 0, the system knows that the object is not required to use     //     The Add method   adds a reference count     [obj addObject:obj1];    [obj  Addsubview:obj1];    //    remove will reduce the object reference count     [obj  removeObjectAtIndex:0];    [obj removeFromSuperview];         //    NSAutoreleasePool  Auto-release pools can help track objects that need to be released for some time to delay, By sending an drain message to the auto-release pool, the auto-free pool is cleaned up and the object is freed//    [obj1 autorelease];         Fraction *frac1 = [[Fraction alloc]init];     Fraction *frac2 = [[fraction alloc]init];    //    [frac1 release];//     [frac2 release];            }-( void) autoarc{}-  (void) didreceivememorywarning {    [super  Didreceivememorywarning];    // dispose of any resources that  can be recreated.} @end


OC17 memory management and automatic reference counting

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.