difference between ARC and MRC

2019-04-28 02:12发布

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 ?

2条回答
beautiful°
2楼-- · 2019-04-28 02:48

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.

查看更多
叛逆
3楼-- · 2019-04-28 03:15

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
}
查看更多
登录 后发表回答