3 ms·
"ARC is awesome, but I highly suggest that you don’t use it until you can manage memory yourself. In other words, don’t rely on ARC until you understand what it
by commanda 15y ago
"ARC is awesome, but I highly suggest that you don’t use it until you can manage memory yourself. In other words, don’t rely on ARC until you understand what it’s doing."
This is not good advice.
ARC is meant to free the programmer from having to think about memory management and allow us to instead think about what we're trying to express in our object graphs and algorithms. Deciding where to call retain and release is an old, tired dance and is where the vast majority of memory leaks and app crashes come from. With ARC, we can just relax and let the compiler insert all those pesky retains and releases where it knows they should go.
There is no reason for newcomers to learn the old style. If a newcomer is reading old-style code, she can skip over the retain/release calls and pretend they're not even there, because they don't affect the algorithm.
- Aqua_Geek 15y agoI agree with the general sentiment, but you're not free from all memory management. If I've never learned about it, how do I know when to make something strong vs weak? How about bridging from CF types? ARC is a step in the right direction, but it doesn't free newcomers from ever learning about memory management.
- commanda 15y agoApple's ARC documentation explains how to deal with those kinds of things. It's as accessible to an iOS beginner as retain/release are, perhaps more so. Specifically, regarding strong vs weak, the point is that you are to think about your object graph instead of thinking about memory management.
- nupark2 15y agoI very strongly disagree. ARC still reveals the underlying nuts and bolts, necessitating a basic understanding of reference counting systems. It doesn't solve retain cycles, thus requiring the judicious use of __weak in cases where a retain cycle may emerge. Determining where such a cycle may occur requires understanding reference counting. This significantly impacts your expression of algorithms where the simplest/best implementation may involve cyclic object graphs. Additionally, ARC does not handle mixing CoreFoundation and Foundation code directly, requiring one to manually express bridging rules based on an understanding of reference counting. It may be that ARC gradually smooths out its rough edges, and we find ourselves in a situation similar to GC, where developers need only understand the difference between weak and strong references, and the opportunities that exist there for leaks caused by maintaining strong live references. However, we're still a bit far from that point, and newcomers should remain well-aware of retain/release and the vagaries of reference counting systems.
- rpwilcox 15y agoI agree (with you, nupark) For example, thr other day I was debugging a crash in my Cocoa (ARC) app. I've been programming Cocoa since 10.1, although I stepped away for a few years. Anyway, random crash. My "manage memory manually" training knew it was an object getting released too early: I know I needed to retain it. Think think think... Of yes, my @property declaration was missing a retain declaration. Of course cocoa was releasing that object! ARC sure helps, and between it and use of the autorelease pool (thanks Brent Simmons!) I hardly have to worry about memory management at all - except when I do, then I need to know what ARC is or is not doing behind the scenes.
- DrJokepu 15y agoHere in Europe we almost exclusively drive standard shift cars only. In fact, I've never driven an automatic shift car until very recently when I've visited my American girlfriend's parents the first time and found that's it's simply impossible to rent a standard shift car in the US. After a few hours I had to realise that modern automatic transmission systems these days are so good that unless you have special needs, there's simply no need to drive or even to learn to drive stick shift anymore. They're incredibly smooth and clever and completely abstract away the complexity of changing gears. It's like magic. However, ARC is not quite there yet. It's a very useful tool but it's still a rather imperfect abstraction. You have to understand the problems with loops in object graphs, strong and weak references and why they're needed, bridging and all the other things ARC can't do for you yet. Maybe in a few years it will be possible to completely forget about memory management but today you simply cannot write a well behaving Objective-C application without understanding what's happening under the hood when it comes to memory management.
- atomicdog 15y agoThen what happens when you inevitably need to work on a project that doesn't use ARC?