Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!labrea!polya!shap From: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Newsgroups: comp.lang.c++ Subject: Re: Exception Handling (was: Overloading operator new()) Keywords: garbage collection scope Message-ID: <4383@polya.Stanford.EDU> Date: 10 Oct 88 18:58:09 GMT References: <5949@june.cs.washington.edu> <294@itivax.UUCP> <797@nih-csl.UUCP> <298@itivax.UUCP> <4370@polya.Stanford.EDU> <301@itivax.UUCP> Reply-To: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Organization: Stanford University Lines: 33 In article <301@itivax.UUCP> scs@itivax.UUCP (Steve C. Simmons) writes: >In article <4370@polya.Stanford.EDU> shap@polya.Stanford.EDU (Jonathan S. Shapiro) writes: >>... The big problem I see is that there is no good ordering >>constraint on the destructions. > >It's not clear why order is a problem. Could you explain? The reason ordering is important is that there is a metasemantics to object creation order. Consider a linked list. Destroying the head might be implemented to destroy the rest, but I might be referring to that object someplace else. Consider the following problem that this might lead me to, which I see as the really hard problem here: I instantiate an exception scope, then I create an object (call it Counter) that I am going to use as a counter for the number of Foo objects I have. The Foo constructor appropriately increments the count, the destructor decrements it. If I blow away Counter before I blow away all the Foos I could (potentially) get into trouble (though it will be hard to notice, since the decrement operators are now happening on logically freed memory). The example is contrived. Now imagine that Counter is some object that keeps track of the number of references to itself and deletes itself when appropriate. Such objects are very useful, and could get one into serious trouble here. This example is all too real. Now the metasemantics of the ordering is not readily expressible in the language. How should this problem be addressed? Jon