Linked by Zachary Pinter on Tue 27th Apr 2004 17:09 UTC
General Development Garbage collection (GC) is a technology that frees programmers from the hassle of explicitly managing memory allocation for every object they create. Traditionally, the benefit of this automation has come at the cost of significant overhead. However, more efficient algorithms and techniques, coupled with the increased computational power of computers have made the overhead negligible for all but the most extreme situations.
Permalink for comment
To read all comments associated with this story, please click here.
The real problem is finalizers
by Esben Mose Hansen on Wed 28th Apr 2004 06:53 UTC

Any GC mechanism that depends on finalizers as the only object clean-up method trades an irritant with a real problem. The irritant is memory management. The problem is resource management --- semaphores, files and so on. One of the clean, effective and easy solution is to use constructors and destructors to manage the allocation and deallocation of these resources. This garanties proper deallocation at the proper time, without ever risking accessing deallocated or never-allocated objects. This idea is often nicknamed RAII (Resource Allocation Is Initialization). This technique cannot be used with finilizers, however, which may never be run (at all!)

This does not mean that GC is bad. C++ (which seems to survive everything, beats-me-how) now has several GC availble, including some very interesting "conservative" collectors, which garanties that destruction occurs exactly when the object goes out-of-scope. This is, IMHO, the way to go. This way, wrapper objects can be made which handles nearly resource management --- not just memory.

This is not about performance, though I admit that Java and .NET has problems in this regard. This is about correctness, which is far less easily solved.