home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12624 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.7 KB

  1. Path: sparky!uunet!synaptx!synaptics.com!daveg
  2. From: daveg@synaptics.com (Dave Gillespie)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <DAVEG.92Aug20043156@synaptx.synaptics.com>
  6. Date: 20 Aug 92 11:31:56 GMT
  7. References: <1992Aug6.014619.2111@ucc.su.OZ.AU>
  8.     <DAVEG.92Aug17231725@synaptx.synaptics.com>
  9.     <1992Aug19.180252.12942@mole-end.matawan.nj.us>
  10. Sender: daveg@synaptx.Synaptics.Com
  11. Organization: Synaptics, Inc., San Jose, CA
  12. Lines: 49
  13. In-reply-to: mat@mole-end.matawan.nj.us's message of 19 Aug 92 18:02:52 GMT
  14.  
  15. In article <1992Aug19.180252.12942@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
  16.  
  17. >>   Is there really so much harm in allowing the C++ runtime
  18. >>   system to delete the object in that circumstance?
  19.  
  20. > You've answered your own question in the negative.  If the destructor
  21. > has an effect on the program's output, and it is accidentally called
  22. > by the GC instead of by its proper deletion, the program's output will
  23. > depend on the exact properties of the GC system and the exact sequencing
  24. > of internal states of the program and of the program's runtime internals'
  25. > states.  It might work correctly by accident in testing, and fail
  26. > disastrously in service.
  27.  
  28. Sorry, I didn't make myself clear.  I realize that allowing GC to call
  29. a destructor would add one more case where destructors with side effects
  30. could surprise the C++ programmer.  My question was, is that potential
  31. for surprise enough to kill the idea of garbage collection in C++?
  32.  
  33. My answer is no, it just means C++ programmers who use garbage collection
  34. have to be a little careful about what they put in their destructors.
  35.  
  36. > Allowing GC to operate destructors is not safe.
  37.  
  38. Only if "new" statements in existing programs create collectable objects.
  39. If you have to do something special, like say "GCnew" (admittedly not the
  40. most pleasing notation), then existing programs won't break, and the
  41. chapter on garbage collection just has to include a caveat that if you
  42. allocate an GC-able object with a destructor that has side effects, you'd
  43. better watch out because you can't know when those side effects will
  44. occur.
  45.  
  46. > Not allowing GC to operate destructors does not suit C++'s model of
  47. > execution.
  48.  
  49. Agreed.  For example, an object giving access to a file wants to close
  50. the file when it's collected.  A class might want to keep statistics
  51. on how many instances of the class are currently allocated, etc.
  52.  
  53. > Think about it.
  54.  
  55. I did; as far as I can tell, the GC has to call destructors, and it's
  56. acceptable for it to do so as long as it doesn't break existing code,
  57. which can be done by introducing something like "GCnew".  Simple as that.
  58.  
  59.                                 -- Dave
  60. --
  61. Dave Gillespie
  62.   daveg@synaptics.com, uunet!synaptx!daveg
  63.   or: daveg@csvax.cs.caltech.edu
  64.