Bug 1207 – Documentation on destructors is confusing
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-05-01T02:10:00Z
Last change time
2014-02-16T15:22:24Z
Assigned to
bugzilla
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2007-05-01T02:10:54Z
The documentation under class.html#destructors states:
"""
When the garbage collector calls a destructor for an object of a class that has members that are references to garbage collected objects, those references are no longer valid. This means that destructors cannot reference sub objects. This rule does not apply to auto objects or objects deleted with the DeleteExpression.
"""
This is unclear. Which "objects" does the last line refer to? Does it mean sub-objects? Does it mean that calling delete on a sub-object in your destructor is ok? If it's really saying that it's a bad idea to *ever* refer to a pointer sub-object in *any* way in a destructor, then I think that fact should be stated much more clearly in big bold font. Particularly it should be crystical clear on whether it's ok to call delete on your sub-objects, since this is what all C++ programmers do by reflex in their destructors.
Comment #1 by bugzilla — 2007-07-01T14:00:38Z
Fixed DMD 1.018 and DMD 2.002
Comment #2 by wbaxter — 2007-07-01T14:23:12Z
It's better, but now there's a little typo:
"""
This is because that the garbage collector ...
"""
Also the explanation seems to be a little out of order now.
It says this:
"""
The garbage collector is not guaranteed to run the destructor for all unreferenced objects. Furthermore, the order in which the garbage collector calls destructors for unreference objects is not specified.
"""
*after* having already said in the previous paragraph: "the garbage collector does not collect objects in any guaranteed order". I think the above paragraph should be moved before the paragraph that explains why you can't reference sub-objects.