www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf
Furthermore, the only "advantage" I see in garbage collectors is that they can deal with cycles.
I say "advantage" because i'm of the strong opinion that having a cycle in your code is a software design error.
Also I would say that it's very uncommon to do/need something like this so it shouldn't be cited as an reason for cycles to be generally handled.
It is performance wise infeasible to avoid that circular reference because it is very easy to pull back a lot of data from entity framework and change none of it.
I have to disagree with your second statement, ref-counting is extremely fast. If you consider it a GC then it's the fastest GC. It's also deterministic and does not pause.
No, it's not, not unless you use a lot of cleverness. "We find that an existing modern implementation of reference counting has an average 30% overhead compared to tracing…" (They did perform a lot of optimizations to get it up to speed with tracing garbage collection... however, these are far beyond what shared_ptr does.)
http://users.cecs.anu.edu.au/~steveb/downloads/pdf/rc-ismm-2...
Of course, you could queue up and lazily delete the resources, but then you're back to nondeterministic behavior.
With refcounting you have:
- Slow memory allocations (need to manage a fragmented heap)
- Slow accesses and pointer handovers (updates to the refcounter)
- Slow free (need to manage the free list)
- No asynchronous pauses (since there is no garbage collector)
With a GC, you get: - Fast allocations (usually just an "add" instruction since the heap is not fragmented)
- Zero cost accesses and pointer handovers
- Zero cost free (just stop using the pointer)
- Some asynchronous pauses and CPU usage while running the GC
It turns out that the cost of the first three points when using refcounting are much higher than that of the GC. Another reply to your post included references to actual research on this subject.