home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!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.715021105@siria>
- Sender: news@parc.xerox.com
- Organization: Xerox PARC
- References: <DAVEG.92Aug20043156@synaptx.synaptics.com> <28623@vedge.UUCP> <DAVEG.92Aug28004331@synaptx.synaptics.com>
- Date: 28 Aug 92 16:58:25 GMT
- Lines: 47
-
- daveg@synaptics.com (Dave Gillespie) writes:
- >This all reminds me of the idea of "finalizations" in Lisp, a
- >simple-sounding and very useful concept that turns out to be a
- >horrible quagmire of complications when it is implemented.
-
- >Basically, a finalization is a property that can be attached to
- >any allocated object, which is a function to be called to clean up
- >when that object is garbage-collected. In other words, it's a
- >destructor.
-
- ...
-
-
- >If you made a linked list of N things each of which had destructors,
- >it would still take N GC's to delete the list, but the idea is that
- >destructors (finalizations) would only be used for the kinds of
- >things that are not used in big lists. For example, a finalization
- >might close a file that was held open by the object; rarely would
- >you have a linked list of 1000 objects each holding open a file!
- >(And where the links are in the objects themselves; a conventional
- >Lisp list of pointers to finalizable objects would have no problem,
- >because the cons cells themselves have no finalizations and so can
- >be collected all at once.)
-
- Cedar does something similar. (So does the latest version of
- our conservative stand-alone collector.) Empirically only on the order of
- 100 objects (in a 15 MB or so heap) are finalizable at any given point,
- and there tends not to be a lot of connectivity between them, for
- precisely the reasons you describe. The most serious (but not
- unsolvable) problem is dealing with cycles of finalizable objects.
-
- PARCPlace Smalltalk uses a different approach in which a proxy
- object is notified of the death of the object it watches. That's
- also quite reasonable. But it also doesn't suffice to deal with the
- circularity issue.
-
- Another issue is that at least Cedar finalization allows finalization
- to be reenabled on resurrected objects. This argues perhaps that
- finalization and destructors aren't exactly the same. (My
- impression is that C++ destructors also get used instead of
- something like the Modula-3 try ... finally construct to perform
- an action on any exit from a block. This use also seems
- orthogonal to finalization, which I view as reclaiming nonmemory
- resources, and doing only that.)
-
- Hans-J. Boehm
- (boehm@parc.xerox.com)
-