
Why use garbage collection - soundsop
http://blogs.msdn.com/abhinaba/archive/2009/01/20/back-to-basics-why-use-garbage-collection.aspx
======
kragen
Extremely basic article, written in poor English, fails to explain the real
reasons GC isn't used in the places where it isn't used, full of vague
pronouncements ("it makes execution flow very un-predictable and hence GC
becomes almost mandatory").

And it misses the big advantages of garbage collection: by allowing you to
handle arbitrary-sized data structures as easily as if they were integers, it
makes your programs easier to understand — not just easier to read!

Not worth reading.

~~~
kragen
Um, where I was complaining about the quality of the prose in the original
article, I wrote "not just easier to _read_ " when I meant "not just easier to
_write_ ". Serves me right, I guess.

------
zandorg
I wrote a C++ class (compatible with STL's vector class), and it had an
internal reference counter. If the counter went to 0, it would de-allocate the
memory and shut the vector down. It works pretty well, and avoids the need for
a garbage collector.

It uses constructors and destructors to achieve this.

~~~
s3graham
That "works" (minus circular references) in simple cases, but it still has bad
worst case performance (if your decrements chain, causing many decrements and
frees).

And in something like boost::smart_ptr, the cache performance is awful because
the increment/decrement is an extra indirection in a separate allocation,
which is getting hit constantly.

~~~
newt0311
Actually, general malloc performance is horrible and that refcounting
implimentation will be the absolute worst. In an accurate GC, the objects can
be moved around in memory for more efficient allocation. Add support for
generations and it becomes significantly faster than manual allocation.
However, refcounting misses all of that and screws up on circular referrences
to boot.

~~~
s3graham
"Actually," normally starts a disagreement, but AFAICT, you restated what I
said and agree. Or do I misunderstand?

~~~
newt0311
Sorry, you are right. It's my bad grammer getting to me again.

------
rw
What are the effects of GC on hard real-time systems (NASA rovers, power
plants)?

~~~
coryrc
If the maximum GC time is less than the minimum response time, nothing. If
not, the system is non-compliant and can fail.

------
miratom
I hate the whole argument of the "problem" of hanging/dangling pointers as
reason for GC. Is GC only for covering up your n00b mistakes? GC will never be
a reasonable management scheme for realtime or limited memory systems, where
programmer responsibility and predictable behavior is required.

~~~
brl
In the case of dangling pointers, garbage collection just converts a potential
heap corruption bug into a probable memory leak instead. Not really an obvious
win. At least in C you have to be conscious of memory management in order to
successfully write programs that don't crash.

------
newt0311
Now, with real-time GC systems comming to light and mature GC implementations
in VMs like hotspot and conservative GC (boehm GC) for languages like C, I
think the correct question is why _not_ to use GC.

~~~
silencio
When it's not yet available...like on the iPhone.

~~~
newt0311
The iPhone has access to some modern VMs which have GC.

