开发者

Should I use ARC in objective-c?

开发者 https://www.devze.com 2023-03-28 17:19 出处:网络
Looking at the release notes of OS 10.7, there\'s some stuff about using Automatic Reference counting (ARC) to make memory management simple. I\'m about to embark on a new Cocoa project soon and wonde

Looking at the release notes of OS 10.7, there's some stuff about using Automatic Reference counting (ARC) to make memory management simple. I'm about to embark on a new Cocoa project soon and wondered whether it would be worth using the model (the way I understand it, you can't mix between using ARC and not using it)?

The dilemma seems to be using something new versus using something that could potentially save lots of debugging time later. But is that the case? Has anyone played around with it and fou开发者_Python百科nd no real-world benefit?


Without a doubt you should use ARC. ARC injects the retain release calls at the most appropriate times, so you may actually see lower average memory use than you would if you didn't use ARC.

I have used ARC and it is immensely powerful. You stop having random crashes and your app just feels more responsive. As they said at WWDC, there is no reason not to use Automatic Reference Counting.

Also, you can use non-ARC files in the same project as ARC files.


I agree with FreeAsInBeer about using ARC. However, it should also be made clear that garbage collection (GC) should not be used. It looks like Apple is henceforth going to focus their efforts ARC, while letting GC die a slow death. This is wonderful because ARC is clearly a far superior technology, whereas GC is slow and extremly buggy.

So yes. Use ARC. Stay away from GC.

0

精彩评论

暂无评论...
验证码 换一张
取 消