4 ms·
I don't see how the concurrency claim makes any sense. Many concurrency primitives revolve around counts (for example, a semaphore). Likewise, GC may be able t
by strmpnk 15y ago
I don't see how the concurrency claim makes any sense. Many concurrency primitives revolve around counts (for example, a semaphore).
Likewise, GC may be able to deal with messy situations (ones that I'd advise you avoid anyway), but brings problems too like non-deterministic lifetimes. ARC isn't a silver bullet but I think it gets pretty close to how people use GC in day to day software.
- chc 15y agoWith reference counting, each strong assignment has to alter at least one object's reference count in a thread-safe manner. With garbage collection, you can just assign — a fast, atomic operation. Also, one of those "messy situations" that you'd advise us to avoid is the nigh-ubiquitous Cocoa controller-delegate pattern. That's a circular reference. With ARC, you have to explicitly break it. It's not a big darn in general, but it's a definite weakness of retain counting. My point is that it's a massive hyperbole to call ARC "garbage collection without any of the nasty downsides."
- strmpnk 15y agoReference counting has plenty of instruction specific atomic operations on common processors in use today (and no, GC routines need write barriers in most cases that atomic counting is needed). But you're right, it's tricky, but that's why it's important to make all of that automatic and transparent to the programmer. Delegation patterns are complex for lifetime management though that is why they have spent a good portion of their documentation on helping people understand when to use zeroing weak references which is a very easy fix for problems like this. Their heuristics work better than I imagined here. Still trickier than GC but much more consistent. So far the downsides are pretty small relative to manual memory management and close to GC without trading off the consistency of manual memory management. I'd say "garbage collection without any of the nasty downsides" is more accurate in this case than not.