From: Jim Weirich Date: 2002-02-25T05:05:43+09:00 Subject: Re: Object/Memory Management >>>>> "SeanM" == Sean Middleditch writes: SeanM> [...] The stack does *not* in any way guarantee that those SeanM> objects are cleaned up. You can leave functions without SeanM> cleaning up (destroying) objects on the stack. Errors or SeanM> exceptions can occur during stack cleanup that you can't SeanM> catch or deal with. The order of object destruction is (in SeanM> many compilers) not guaranteed. [...] Actually, if we are talking about stack based C++ objects here, this is incorrect. The order of destruction of stack based objects is always reverse order of creation. They are guaranteed to be destructed upon leaving the scope of the function, even in the presence of exceptions (setjump/longjump does cause problems). Since C++ doesn't have a finally statement, or easy to use closures, the stack based destructor trick is used pervasively. Many C++ programmers try to take this technique with them when trying other languages. Unfortunately, I've only seen it work effectively in C++ -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)