Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC, worth it or not?

When I moved to Objective C (iOS) from C++ (and little Java) I had hard time understanding memory management in iOS. But now all this seems natural and I know retain, autorelease, copy and release stuff. After reading about ARC, I am wondering is there more benefits of using ARC or it is just that you dont have to worry about memory management. Before moving to ARC I wanted to know how worth is moving to ARC.

  1. XCode has "Convert to Objective C ARC" menu. Is the conversion is that simple (nothing to worry about)?
  2. Does it help me in reducing my apps memory foot-print, memory leaks etc (somehow ?)
  3. Does it has much testing impact on my apps ?
  4. What are non-obvious advantages?
  5. Any Disadvantage of moving to it?
like image 723
msk Avatar asked Mar 26 '12 16:03

msk


People also ask

Is the Sonos Arc really that good?

The Sonos Arc is a good overall soundbar from 2020. This standalone soundbar can be easily upgraded into the Sonos Arc with Sub + One SL Speakers with the addition of a wireless subwoofer and surround satellites for an even more immersive experience.

Is Sonos Arc worth?

Is the Sonos Arc Worth the Money? Yes, it is! At first glance, it might seem overpriced, especially considering the limited connectivity options. However, the sound quality and clarity are worth the hefty price tag.

Is it worth getting a sub with the Sonos Arc?

The Sonos Arc with Sub + One SL Speakers is a very good overall soundbar. It sounds well-balanced right out of the box and features a lot of customization tools to make it sound the way you want. It's a premium-feeling soundbar setup that has an amazing surround and good Atmos performance.

Can Arc support Dolby Atmos?

ARC can, however, allow you to receive Dolby Atmos audio from streaming services such as Netflix, Disney Plus and Amazon Prime Video, as these services embed Dolby Atmos in the lossy Dolby Digital Plus format which ARC can handle.


4 Answers

Here's my specific take on ARC:

1) XCode has "Convert to Objective C ARC" menu. Is the conversion is that simple (nothing to worry about)?

It's simple. It works. Use it. As Kevin Low points out though, you will need to go through and fix up the bits where you use Core Foundation objects. That will just require a healthy lashing of __bridge or __bridge_transfer though.

2) Does it help me in reducing my apps memory foot-print, memory leaks etc (somehow ?)

Nope, not really. OK, sort of. It will help reduce memory leaks where you have coded incorrectly previously. It won't reduce memory footprint.

3) Does it has much testing impact on my apps ?

None whatsoever.

4) What are non-obvious advantages?

The future. There'll be more to come on the bonus that the compiler taking an intricate knowledge of how objects are reference counted gives. For example ARC provides the lovely objc_retainAutoreleasedReturnValue optimisation already, which is very nice.

5) Any Disadvantage os moving to it?

None whatsoever.

Please take my word for it and start using ARC. There's no reason (IMO) not to, thus the advantages definitely out-weigh the disadvantages!

For an in-depth look at how ARC works to perhaps help convince you that it's good, please take a look at my blog posts entitled "A look under ARC's hood" - here, here, here & here.

like image 163
mattjgalloway Avatar answered Oct 27 '22 12:10

mattjgalloway


Here's what you really need to know about ARC:

The compiler understands Objective-C and Cocoa better than you. I don't mean this as an insult; it understands it better than me. I think you could safely say it understands the rules better than all but maybe a dozen people worldwide. And it knows tricks to use them to a degree that you and I can't repeat, even if we understood as well as it does.

The rest is just details:

  • You will write a lot less boring code. Code so boring it's easy to make mistakes.
  • As a blended compile time and run time process, it has access to tricks that you don't.
    • It will a better a job of writing memory management code than you can, even if you write the theoretical perfect memory management code.
    • It will reduce "high tide" memory usage (somewhat) without any effort on your part.
    • With zeroing weak references, it's much easier to avoid crashes caused by dangling pointers.
  • If you are starting a new application, stop thinking about it and just use it.
  • If you have an existing application:
    • You will need to re-test it. You need to make sure you have no circular references.
    • If you have an existing application that targets iOS before iOS 5, zeroing weak references are not supported. You should seriously consider requiring iOS 5.
    • If you have an existing application that targets iOS before iOS 4, you can't use it at all. What are you thinking, supporting crap that old?!?
  • In the last version of Xcode, it was not entirely bug free. It probably still isn't. But it's still worth using.
like image 30
Steven Fisher Avatar answered Oct 27 '22 13:10

Steven Fisher


  1. If you're using Core Foundation or non-Objective-C code, then it's not as simple as you will have to manually go through your code and make sure all the casts between Objective-C and Core Foundation are bridged (if you have any casts). You'll also still have to manage memory for non-Objective-C code.

  2. It's supposed to essentially take care of all memory leaks for you, since it automates the retain, release, copy, etc. So far, I've never had an Objective-C leak since switching to ARC.

  3. No. Building might take a tad bit longer since it has to go through all your code and insert all the retain and release code.

  4. Not sure if there are any. In the end, all ARC is, is an automator.

  5. You will have to learn about bridged casts as well as you cannot build for anything lower than iOS 4.

In the end, it's definitely worth it. I was skeptical at first, but after watching the WWDC video where they explain how it works, I liked it more and more.

like image 27
Kevin Low Avatar answered Oct 27 '22 12:10

Kevin Low


Have you read Apple's documentation on ARC? It answers a lot of the questions you're asking.

Based on my experience, here's what I think:

  1. Yes, it's simple. You definitely need to test your app after converting, though.
  2. It can help reduce your app's memory usage and leaks, but it's not guaranteed to do that.
  3. Yes. You'll want to test after converting to ARC.
  4. You don't have to waste as much time thinking about and tracking down leaks. You can spend more time and energy on your app's actual code, rather than worrying about retain/release. Even if retain/release code is natural and easy for you, you're not infallible and you'll occasionally forget to release something. ARC doesn't forget.
  5. If you're supporting iOS 4, you'll have to handle weak references, as ARC doesn't support those in iOS 4.
like image 26
Josh Brown Avatar answered Oct 27 '22 13:10

Josh Brown