Re:Garbage Collection is Wrong
by rian on Thursday February 27, 2014 @04:45PM
(#7315345)
Yes I think you would use a ref counted resource in that case. For your tangled mess of database connections I can't imagine ref counting not being adequate in those scenarios as well.
[ Parent
| on HN ]
And now we are back at garbage collection - the two main options are reference counting GCs and collecting GCs. I know it for the .NET GC, they tried a reference counting GC and it performed worse than a collecting GC and not to forget the trouble with cycles when implementing a reference counting GC.
And reference counting also renders the point of determinism moot - now you never know if releasing a reference while trigger freeing a resource. You could of course delay offload it to a separate thread, but this makes you lose any guarantee about the time when the resource is actually freed, too.
> And reference counting also renders the point of determinism moot - now you never know if releasing a reference while trigger freeing a resource.
You know that releasing the last reference will. That is why the important concept is single ownership of resources and not reference counting by itself.
But you don't know which reference is the last until you actually get there - that is why you used reference counting in the first place, because you were unable to statically determine which reference will be the last one. So every time you abandon a reference it might be the last one and you might have to spend extra cycles to free the resource. This is no more deterministic than a garbage collector.
In a non-deterministic garbage collector memory _might not_ be released when the last reference goes out of scope (and this is often the case).
Ah, I don't think ref counting is generally considered GC. It's more like RAII and used in C++ elsewhere via shared_ptr.