difference between ARC and MRC

2019-04-28 02:51发布

问题:

I am confused with Apple material.

In 3 ways we manage the memory, they are :

  1. automatic referance counting.
  2. manual reference counting.
  3. garbage colletion.

My doubt is what is the difference between automatic reference counting and manual referance counting.

Can someone explain me ?

回答1:

In ARC you don't have to release/autorelease the memory allocated by you where as in case of manual you have to take care of this. e.g. manual case

-(void)someMethod
{ 
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    //use array
    [arr release]; //when array is in no use
}

ARC case

-(void)someMethod
{
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    //use array
}


回答2:

In ARC the OS looks after the memory management, so you don't have to worry about releasing the objects. It's pretty neat for beginners. Whereas in Manual counting you will have to keep track of releasing the memory and if you don't do it right you will end up crashing your app. ARC and MRC are available in ios where as garbage collection is limited to MAC-OSX hope this helps. Inder has given a good example.