1

Possible Duplicate:
iOS: to ARC or not to ARC? Pros and Cons

i have learned about What are the advantages and disadvantages of using ARC?

from What are the advantages and disadvantages of using ARC?

However i still doubt in automatic reference counting (ARC).

I have some queries here.

We don't want to do the release manually, if the ARC is active?

is it do the automatic garbage collection and memory management automatically?

Could any one please clarify my thoughts.

Community
  • 1
  • 1
Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
  • The article you've described pretty much sums it up nicely. That is to say, if you don't wish to manually manage your reference counts, then enable ARC and you don't have to. – Jeremy Mar 13 '12 at 15:24
  • @Caleb: i didn't find the mentioned link earlier. sorry for duplicated it. – Shamsudheen TK Mar 13 '12 at 16:22
  • @Ramshad No problem -- that's why I pointed it out. This question will probably be closed as a duplicate. That doesn't mean it's not a good question, only that it's already been asked and answered. Closing duplicates helps good answers accumulate all in one place and makes them easier to find. – Caleb Mar 13 '12 at 16:28
  • ho.thanks for duplicated it :) – Shamsudheen TK Mar 13 '12 at 16:34
  • I had some great answers to my question on this topic - they may be of use to you too? http://stackoverflow.com/questions/8760431/ios-to-arc-or-not-to-arc-pros-and-cons Hope this helps :) – Simon Withington Mar 13 '12 at 15:24

2 Answers2

2

ARC is not a garbage collector. Apple describes it as:

Automatic Reference Counting (ARC) is a compiler-level feature that simplifies the process of managing object lifetimes (memory management) in Cocoa applications.

So what ARC does it's just adding the retain/release calls while compiling. This helps the developer to save time and skip the writing of deallocs and other memory management calls.

Even if ARC helps a lot, this doesn't mean that a developer should ignore memory management. Sometimes, it's rare, but it happens, ARC is not able to figure out what to do and could generate unexpected behaviors. It's definitely a great tool, but it's better to understand the whole memory management routine in Objective-C before activate it and let it do its magic.

bontoJR
  • 6,995
  • 1
  • 26
  • 40
  • 1
    I'll have to agree. Understanding memory management is empowering and you've got more control. – Jeremy Mar 13 '12 at 15:35
  • @junior B: thanks for the insightful info – Shamsudheen TK Mar 13 '12 at 16:23
  • your welcome, I forgot to mention the fact that ARC doesn't handle Core Foundations objects (like Core Graphics, Contacts from Address Book, etc...). This question and the detailed answer should help: [Does ARC work with Core Graphics objects?](http://stackoverflow.com/questions/7800174/does-arc-work-with-core-graphics-objects) – bontoJR Mar 13 '12 at 21:29
1

To answer the specific questions

We don't want to do the release manually, if the ARC is active?

No, in fact it would be a compiler error to use retain, release or autorelease when you are using ARC.

is it do the automatic garbage collection and memory management automatically?

Kind of, what it actually does is use the clang static analyser to put the retains and releases in for you, so it is a kind of garbage collection but not like a traditional garbage collector. In that respect, it is like a garbage collector because you don't need to worry about putting your own retains and releases in, but on the other hand, unlike a real garbage collector, strong reference cycles (previously known as retain cycles) will still cause leaks.

JeremyP
  • 84,577
  • 15
  • 123
  • 161