Destructor nonsense on dlang.org
Tove
tove at fransson.se
Thu May 24 10:47:31 PDT 2012
On Thursday, 24 May 2012 at 17:06:19 UTC, ponce wrote:
> I really had a hard time to believe it when #D told me so, but
> there is no guaranteed order of destruction and as you cannot
> relies on members still being alive in a class destructor.
> All of it can happen when making absolutely no cycles in the
> object graph.
>
> What I do now is having a close function for each class which
> hold a non-memory resource.
>
> This is writtent in TDPL, but I wish I was told earlier :)
http://dlang.org/class.html#destructors
"This rule does not apply to auto objects or objects deleted with
the DeleteExpression, as the destructor is not being run by the
garbage collector, meaning all references are valid."
i.e. non gc resources are fine... and it's also fine if you call
clear()... it's only a problem if you rely on automatic
collection and reference a object... so there's no need for
close, as clear() will do the trick.
More information about the Digitalmars-d
mailing list