ARC, worth it or not?

前端 未结 7 1528
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 09:53

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, autoreleas

7条回答
  •  感情败类
    2021-02-05 10:12

    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.

提交回复
热议问题