auto classes and finalizers
Jarrett Billingsley
kb3ctd2 at yahoo.com
Wed Apr 5 21:08:43 PDT 2006
"Dave" <Dave_member at pathlink.com> wrote in message
news:e11vjk$1fou$1 at digitaldaemon.com...
> Long and short of it is I like Mike's ideas regarding allowing dtors for
> only
> auto classes. In that way, the GC wouldn't have to deal with finalizers at
> all,
> or at least during non-deterministic collections. It would also still
> allow D to
> claim RAII because 'auto' classes are something new for D compared to most
> other
> languages.
Hmm. 'auto' works well and good for classes whose references are local
variables, but .. what about objects whose lifetimes aren't determined by
the return of a function?
I.e. the Node class is used only in LinkedList. When a LinkedList is
killed, all its Nodes must die as well. Since the Node references are kept
in the LinkedList and not as local variables, there's no way to specify
'auto' for them.
Then you start getting into a catch-22. Okay, so you need to delete all
those child Nodes in the dtor of LinkedList, meaning that LinkedList has to
be made auto so it can have a dtor. But what if a linked list reference has
to exist at global level, or in a struct? There is no function return to
determine when to delete the list. So you have to make LinkedList non-auto,
but then that means that you can't delete all those child nodes since you
don't have a dtor / finalizer, etc..
I think RAII is nice, but it doesn't seem to fix everything. Unless, of
course, it were extended to deal with these odd cases.
More information about the Digitalmars-d
mailing list