by commanda · 14y ago · 0 comments
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.
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.
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.
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.
ARC is a step in the right direction, but it doesn't free newcomers from ever learning about memory management.