auto classes and finalizers

Mike Capp mike.capp at gmail.com
Wed Apr 5 10:51:29 PDT 2006


In article <e10pk7$2khb$1 at digitaldaemon.com>, Sean Kelly says...
>
>I've been following a thread on GC in c.l.c++.m and something Herb 
>posted about C++/CLI today got me thinking:
>
>     - a type can have a destructor and/or a finalizer
>     - the destructor is called upon a) explicit delete or b) at end 	
>       of scope for auto objects
>     - the finalizer is called if allocated on the gc heap and the
>       destructor has not been called
>[snip]
>Might it not be worthwhile to do something similar to the above?  This 
>would allow objects to explicitly delete all their contained data in 
>instances where they are being used as auto objects, rather than always 
>relying on the GC for this purpose.  I'll admit I don't particularly 
>like the idea of separate finalize() and ~this() methods, but it seems 
>an attractive enough feature that something along these lines may be 
>appropriate.

Personally I'm against it. I feel quite strongly that defining a destructor (or
finalizer) should be illegal for a GC type - it should only be allowed for a
class declared as 'auto'. If you need dtor-like behaviour, you should not be
using GC, and the compiler should tell you so.

I posted this opinion some weeks back in a similar discussion here, expecting to
be chased out of town with pitchforks, but the response was very positive.
Nobody could think of any counterexamples, at any rate.

cheers
Mike





More information about the Digitalmars-d mailing list