Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!iuvax!rutgers!bellcore!ctt.bellcore.com!sjs From: sjs@ctt.bellcore.com Newsgroups: comp.lang.c++ Subject: Re: Garbage Collection Keywords: non-religious C++ garbage-collection Message-ID: <12359@bellcore.bellcore.com> Date: 5 Dec 88 16:06:50 GMT References: <5422@polya.Stanford.EDU> Sender: news@bellcore.bellcore.com Reply-To: sjs@ctt.bellcore.com (Stan Switzer) Lines: 48 In article <5422@polya.Stanford.EDU> shap@polya.Stanford.EDU (Jonathan S. Shapiro) writes: > > The advantgage of garbage collection is that it permits storage > reclamation to be the environment's problem, which for some > applications is desirable. > > I have some thoughts on how to do it without changing the semantics of > C++. I would be curious if others think this idea is worth examining > and how they feel it might be done. This is indeed an an interesting problem and we'd best take care to keep it from becoming religious. Certainly there are situations where GC is very useful and others where you want control of memory management. I've been back and forth on this many times myself, but my current feeling is that unless you are writing an operating system or a run-time environment or have hard real-time constraints GC is probably a Good Thing. It can be argued that having to worry about memory management seriously compromises the integrity of the object abstraction. Nevertheless, it is sometimes worthwhile to have control. Of course, nobody ever said that there had to be One Language for all uses. (OK, some people DO say this!) Garbage Collection in C++ raises some interesting issues, though: How does one reconcile the notion of destructors with the idea of automatic GC? After all, destructors can do more than just deallocate memory (closing files and destroying windows, for instance). Should a Garbage Collecting C++ abolish unions and type puns (so as to have a self-describing memory)? Or should one adopt a "sloppy" (cautious?) approach where memory is scanned for things that "look like" pointers and not worry too much? ["How I learned to stop worrying and love the Garbage Collector" -- Dr. Strangehack?] There is a C Garbage collector like this. It makes a few reasonable assumptions and in return the worst mistake it makes is to miss some garbage here and there. It works surprisingly well. Or just possibly we should leave well-enough alone and leave Garbage Collection to other languages. My own thoughts are that GC is best designed into a language rather that tacked-on as an afterthought. Food for thought, Stan Switzer sjs@ctt.bellcore.com "What you can doubt is more important than what you know."