home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12661 < prev    next >
Encoding:
Text File  |  1992-08-20  |  3.3 KB  |  67 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <9223404.28173@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <DAVEG.92Aug17231725@synaptx.synaptics.com>     <1992Aug19.180252.12942@mole-end.matawan.nj.us>     <DAVEG.92Aug20043156@synaptx.synaptics.com> <TMB.92Aug20143223@arolla.idiap.ch>
  9. Date: Thu, 20 Aug 1992 18:02:47 GMT
  10. Lines: 55
  11.  
  12. tmb@arolla.idiap.ch (Thomas M. Breuel) writes about whether GC should
  13. call destructors:
  14.  
  15. >I think the answer is simpler than that. Delete should continue to
  16. >work as it does (including returning memory to the system).
  17. >
  18. >In addition to that, there may be facilities to allow the programmer
  19. >to specify finalization of heap objects that are about to be collected
  20. >but have not been "deleted". Such a facility would not require any
  21. >language changes; something like "gc_set_finalization_hook(void*,void
  22. >(*f)(void*))" might do the trick. Some people may prefer to use such a
  23. >facility simply to detect memory leaks in existing programs, while
  24. >others might want to use it, for example, to release external
  25. >resources.
  26.  
  27. It seems quite clear (to me :-) that objects must be destroyed before
  28. their storage can be reclaimed. The idea that we should have a separate
  29. finalization function that is called instead of the destructor seems to
  30. be a step backwards. I cannot imagine any situation in which the
  31. finalization function would do anything different from the destructor.
  32.  
  33. Exactly the same difficulties with quasi-non-deterministic execution
  34. order apply to a finalization function called during gc as apply to the
  35. destructor being called during gc.
  36. Unspecified order of execution of destructors for GC'ed objects does
  37. not appear to be much of a problem to me; we already have unspecified
  38. order of execution for arguments to a function call, etc., and
  39. destructors generally don't have side-effects apart from resource
  40. de-allocation, so they are generally don't interact with each other.
  41.  
  42. The only advantage of having a finalization function instead of calling
  43. the destructor seems to be that for optimization purposes, it is may be
  44. desireable to optimize the common case when the destructor is empty
  45. (does nothing). However this should not be too difficult for any but
  46. the most naive implementations.
  47.  
  48. Furthermore, for MY code, the finalization function version would
  49. result in LESS efficient code, because if the destructor version wasn't
  50. in the language, then I would have to simulate it manually, by having
  51. the finalization function explicitly call the destructor. This is very
  52. messy as well as being less efficient. Having a finalization function
  53. which I have to remember to install every time I call gc_new is both
  54. tedious and error-prone.
  55.  
  56.     void f (iostream &);
  57.     f(*gc_new fstream(...));    
  58.     // Oops! Forgot to write and install a finalization function
  59.     // for the fstream allocated with gc_new.
  60.     // The file may never get closed.
  61.                         
  62. -- 
  63. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  64. This .signature VIRUS is a self-referential statement that is true - but 
  65. you will only be able to consistently believe it if you copy it to your own
  66. .signature file!
  67.