auto classes and finalizers
Sean Kelly
sean at f4.ca
Wed Apr 5 09:00:57 PDT 2006
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
Given that D can have lexical destruction of objects that weren't
explicitly designed for it, ie.
class C {}
auto C = new C();
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.
Sean
More information about the Digitalmars-d
mailing list