home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
- From: tmb@arolla.idiap.ch (Thomas M. Breuel)
- Newsgroups: comp.lang.c++
- Subject: Re: Garbage Collection for C++
- Message-ID: <TMB.92Aug28201339@arolla.idiap.ch>
- Date: 29 Aug 92 00:13:39 GMT
- References: <DAVEG.92Aug20043156@synaptx.synaptics.com> <28623@vedge.UUCP>
- <DAVEG.92Aug28004331@synaptx.synaptics.com>
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 35
- In-reply-to: daveg@synaptics.com's message of 28 Aug 92 07:43:31 GMT
-
- In article <DAVEG.92Aug28004331@synaptx.synaptics.com> daveg@synaptics.com (Dave Gillespie) writes:
-
- A C++ garbage collector could make itself destructor-safe using
- the same strategy. When the GC finds an object is garbage and the
- object has a destructor, it simply calls the destructor and then
- somehow sets a flag showing that the object has effectively been
- converted to raw bits. The next GC will finally collect the
- object's memory. I doubt such a flag would be difficult to add;
- allocated objects would need a place to record enough RTTI to find
- the proper destructor anyway.
-
- I'm sorry to be so repetitive, but _please_ understand that there is
- no a priori relationship between destructors and finalization.
- Destructors are a C++ language concept specifically linked to blocks
- and the explicit use of "operator delete". This should not change in
- any way. In particular, the GC should not finalize objects by calling
- the destructor, since destructors have not written with that use in
- mind.
-
- If the user wants the finalization code to call the destructor, he can
- do this explicitly.
-
- But wait---don't most classes have destructors? Yes, at present,
- but I claim that GC would render most destructors obsolete.
- Destructors tend to be used for cleaning up auxiliary memory, a
- task which would be automated by GC. Destructors in a C++ with
- GC would be just as rare as finalizations are in Lisp.
-
- Exactly. And for existing classes in which the destructor only
- deallocates, there is no need to call it during a GC. On the other
- hand, for existing classes in which the destructor, say, destroys a
- file descriptor or a window, generally the right thing is to insist
- that the programmer continue to call "delete" manually.
-
- Thomas.
-