Le 24/05/2012 18:10, Alex Rønne Petersen a écrit :
On 24-05-2012 18:06, Andrei Alexandrescu wrote:
It does matter because a destructor may use an object that has just been
destroyed.
Andrei
No, the docs specifically state that this is invalid (and it currently
throws InvalidMemoryOperationError in most cases).
Whether it *should* be allowed is arguable, but it isn't currently, both
in docs and impl.
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 :)