home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsc!cbfsb!att-out!pacbell.com!decwrl!parc!boehm
- From: boehm@parc.xerox.com (Hans Boehm)
- Subject: Re: Garbage Collection for C++
- Message-ID: <boehm.715019515@siria>
- Sender: news@parc.xerox.com
- Organization: Xerox PARC
- References: <DAVEG.92Aug17224359@synaptx.synaptics.com> <boehm.714158406@siria> <DAVEG.92Aug27002517@synaptx.synaptics.com> <4116@seti.UUCP>
- Date: 28 Aug 92 16:31:55 GMT
- Lines: 53
-
- daniel.edelson@goudurix.inria.fr (Daniel Edelson) writes:
-
- >In article <DAVEG.92Aug27002517@synaptx.synaptics.com>, daveg@synaptics.com (Dave Gillespie) writes:
-
- >|> Simple, conservative non-moving GC can be added with
- >|> minimal effect to the rest of the language, and minimal danger of
- >|> toppling it.
- >|>
- >|> Dave Gillespie
-
- >While it is an excellent technique, its worst case behavior is
- >unacceptable, e.g., one false pointer into a very large strongly
- >connected data structure.... It's valuable and worth using, and
- >significantly better than anything else that's currently available,
- >but does not appear to be a panacea. Its presence does not mean
- >that we should stop looking for other solutions.
-
- This touches on another serious issue with garbage collection in C++
- that I haven't seen discussed - namely that of programming style.
- I don't have any experience with large C++ programs. But I have
- seen techniques being advocated that simply don't get along well with
- garbage collection of any form. And they're particularly inappropriate
- with conservative collection. I have no idea whether these are
- considered crucial or not.
-
- My standard example is a list implementation that consists of a
- "linkable elements" class from which one can inherit (possibly multiple
- times) to get a link field added to one's data structure. This
- avoids allocating extra cons-cells for lists. It also leads to a
- situation in which objects contain many link fields for many list
- structures simultaneously. This gives great flexibility in traversing
- the structure, most of which is usually never used. But the garbage
- collector can't determine that. In fact, if you draw some pictures, you
- can convince yourself that if you do enough of this, you are likely to
- eventually connect everything to everything.
-
- I claim this is a problem no matter what form of garbage collector you
- use. In the nonconservative case, all it takes is some client who
- inadvertently hangs on to a tiny component of your data structure, and
- the whole thing gets pinned. Or the compiler allocates a temporary
- that it doesn't destroy soon enough. In the conservative case, you
- also have a problem with a false reference to anywhere in the structure.
-
- I don't think this is an insurmountable problem, since the overhead of
- using cons-cells is probably pretty minimal in reality (and may be
- negative, since you probably didn't really need all those link fields at
- once). But there is a problem with some existing code and programming
- styles here. Interestingly, this seems to be more of a problem with
- C++ code than with C code.
-
- Hans-J. Boehm
- (boehm@parc.xerox.com)
-
-