auto classes and finalizers
Regan Heath
regan at netwin.co.nz
Sun Apr 9 22:08:44 PDT 2006
On Sun, 09 Apr 2006 21:18:45 -0700, kris <foo at bar.com> wrote:
> Regan Heath wrote:
>> On Sun, 09 Apr 2006 19:27:09 -0700, kris <foo at bar.com> wrote:
>>> On the other hand, all these concerns would melt away if the GC were
>>> changed to not invoke the dtor (see related post). The beauty of that
>>> approach is that there's no additional keywords or compiler behaviour;
>> True, however the beauty is marred by the possibility of resource
>> leaks. I'd like to think we can come up with a solution which prevents
>> them, or at least makes them less likely. It would be a big step up
>> over C++ etc and if it takes adding a keyword and/or new compiler
>> behaviour it's a small price to pay IMO.
>
> Regarding leaks, please see related post entitled "GC & dtors ~ a
> different approach" ?
I have. Here is what you say WRT leaks:
> What about implicit cleanup? In this scenario, it doesn't happen. If you
> don't explicitly (via delete or via raii) delete an >object, the dtor is
> not invoked. This applies the notion that it's better to have a leak
> than a dead program. The leak is a bug >to be resolved.
Whereas using my suggestion we get implicit cleanup. Auto propagates as
required, dtors are added and delete is called automatically where
required resulting in no leaks. The best part is that the compiler
enforces that by default and you have to opt-out with 'shared' to
introduce a leak.
So, assuming it's workable (Walters call) and it's not too inflexible I
think it's a better solution. In short, I would rather not have to
explicitly manage the resources if at all possible (and I still hope it
might be).
Regan
More information about the Digitalmars-d
mailing list