Reputation: 131
I am confused with Apple material.
In 3 ways we manage the memory, they are :
My doubt is what is the difference between automatic reference counting and manual referance counting.
Can someone explain me ?
Upvotes: 10
Views: 17196
Reputation: 34235
MRC vs ARC
ARC
inserts retain
, release
, autorelease
instead of developer in compile time. Now you don't worry about manual memory management
Upvotes: 0
Reputation: 317
In MRC, you were responsible for keeping track and making sure that all references of objects were incremented, decremented and deallocated properly. In Obj-C you have basically a set of rules to help you not get any memory leaks or dangling pointers, and it was a considerable effort to make sure that everything was working great, and that could've been automated by something, like some other languages used to.
That's is when ARC get's into the game.
ARC came as an incisive alternative to how things worked with MRC. With ARC, instances are deallocated when there's no strong reference to them, and every instance keeps track of the number of strong and weak/unowned references kept to itself. Although it might look like a similar behaviour, the amount of effort used in both cases are hugely different, in MRC you had to keep track of everything, whereas in ARC the only thing you should do is avoid retain cycles.
Some differences between ARC and Garbage Collector are:
If you want to check for more information, I've found this article to be very helpful:https://swift007blog.wordpress.com/2017/01/14/what-is-arc-in-ios/
Upvotes: 0
Reputation: 12405
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.
Upvotes: 4
Reputation: 39988
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
}
Upvotes: 16