home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13027 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.3 KB

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