Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!att!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.lang.c++ Subject: Re: Eiffel vs. C++ -- Let's drop the garbage collection arguments Summary: A question about C++ GC Message-ID: <9522@alice.UUCP> Date: 23 Jun 89 13:56:03 GMT References: <6590166@hplsla.HP.COM> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 30 There is an important question that needs to be asked in regards to GC of C++ programs: ``When an object is garbage collected should its destructor (if any) be called?'' People often simply assume that the answer is `yes.' This is not obvious. Consider GC as simply a relatively cheap way of achieving an infinite memory. If we had a genuine infinite memory and used `new' and `delete' the constructors for objects allocated using `new' and not deleted would not be called (as C++ is currently defined). In other words, it would still be the programmer's task to call `delete' to trigger the destructor even if memory usage was of no concern. There is therefore two possible models for garbage collection of C++: (1) the `infinite memory' model where destructors are only called for explicitly deleted objects, and (2) the `automatic destruction' model where destructors are called where the memory used to store objects are recycled. The former is more `manual' and more predictable in terms of when things happen. The latter more automatic and (I think) imposes the rule that every object on the free store must be destroyed on normal program termination. I suspect that the programming of destructors will differ significantly dependent on the model adopted.